(function() {
    'use strict';

    /**
     * @ngdoc service
     * @name webApp.myrest
     * @description
     * # myrest
     * Service in the webApp.
     */
    angular.module('webApp')
        .service('dataService', ['$rootScope', '$http', '$q', 'cacheService', 'sessionService', 'authService', 'ERP_CONFIG', 'md5', 'moment', '$filter', 'helper', '$timeout', 'base64',
            function($rootScope, $http, $q, cacheService, sessionService, authService, ERP_CONFIG, md5, moment, $filter, helper, $timeout, base64) {
                var dataService = {
                    reject: reject,
                    promise: promise,
                    resolve: resolve,
                    currentLoginedUser: currentLoginedUser,
                    userCurrentGet: userCurrentGet,
                    login: login,
                    logout: logout,
                    removeAllCache: removeAllCache,
                    removeDataCache: removeDataCache,
                    tpl: tpl,
                    getToken: getToken,
                    userGet: userGet,
                    userOne: userOne,
                    /**********郭 start************/
                    supplierRegister: supplierRegister,
                    supplierLogin: supplierLogin,
                    sellerRegister: sellerRegister,
                    sellerLogin: sellerLogin,
                    acodeGet: acodeGet,
                    acodeunlimitGet: acodeunlimitGet,
                    aqrcodeGet: aqrcodeGet,

                    /**********郭 end  ***********/

                    /**********朱旭 start***********/
                    productcatGet: productcatGet,
                    productcatAdd: productcatAdd,
                    productcatOne: productcatOne,
                    productcatUpdate: productcatUpdate,
                    productcatDelete: productcatDelete,
                    supllerProductGet: supllerProductGet,
                    supllerProductOne: supllerProductOne,
                    supllerProductAdd: supllerProductAdd,
                    supllerProductDelete: supllerProductDelete,
                    supllerProductUpdate: supllerProductUpdate,
                    supllerProductShowUpdate: supllerProductShowUpdate,
                    supllerProductUnshowUpdate: supllerProductUnshowUpdate,
                    partnerGet: partnerGet,
                    partnerAdd: partnerAdd,
                    partnerUpdate: partnerUpdate,
                    partnerDelete: partnerDelete,
                    partnerOne: partnerOne,
                    fenxiaogradeGet: fenxiaogradeGet,
                    fenxiaogradeAdd: fenxiaogradeAdd,
                    fenxiaogradeUpdate: fenxiaogradeUpdate,
                    fenxiaogradeDelete: fenxiaogradeDelete,
                    fenxiaogradeOne: fenxiaogradeOne,
                    fenxiaopriceGet: fenxiaopriceGet,
                    fenxiaopriceAdd: fenxiaopriceAdd,
                    fenxiaopriceUpdate: fenxiaopriceUpdate,
                    fenxiaopriceDelete: fenxiaopriceDelete,
                    fenxiaopriceOne: fenxiaopriceOne,
                    supplerCooperationGet: supplerCooperationGet,
                    supplerCooperationOne: supplerCooperationOne,
                    supplerCooperationAdd: supplerCooperationAdd,
                    supplerCooperationUpdate: supplerCooperationUpdate,
                    supplerCooperationDelete: supplerCooperationDelete,
                    accountGet: accountGet,
                    accountOne: accountOne,
                    memberAccountGet: memberAccountGet,
                    profitGet: profitGet,
                    profitOne: profitOne,
                    returnreportGet: returnreportGet,
                    returnreportOne: returnreportOne,
                    faretempGet: faretempGet,
                    faretempOne: faretempOne,
                    faretempAdd: faretempAdd,
                    faretempDelete: faretempDelete,
                    faretempUpdate: faretempUpdate,
                    attachGet: attachGet,
                    attachDelete: attachDelete,
                    materialGet: materialGet,
                    materialone: materialone,
                    areaGet: areaGet,
                    areaGetById: areaGetById,
                    payConfigAdd: payConfigAdd,
                    payConfigGet: payConfigGet,
                    payConfigUpdate: payConfigUpdate,
                    applyList: applyList,
                    applyupdate: applyupdate,
                    /**********朱旭 end  ***********/

                    /***********王苍 -start*********************/
                    gzhsucatDelete: gzhsucatDelete,
                    gzhsucatAdd: gzhsucatAdd,
                    gzhsucatGet: gzhsucatGet,
                    gzhsutagGet: gzhsutagGet,
                    gzhsutagAdd: gzhsutagAdd,
                    gzhscAdd: gzhscAdd,
                    gzhscDelete: gzhscDelete,
                    gzhscGet: gzhscGet,
                    gzhsutagDelete: gzhsutagDelete,
                    wxappUpload: wxappUpload,
                    wxappSubmit: wxappSubmit,
                    wxappRelease: wxappRelease,
                    ordercountGet: ordercountGet,
                    orderamountGet: orderamountGet,
                    storeGet: storeGet,
                    storeOne: storeOne,
                    storeAdd: storeAdd,
                    storeUp: storeUp,
                    categoryGet: categoryGet,
                    categoryAdd: categoryAdd,
                    categoryUpdate: categoryUpdate,
                    categoryDelete: categoryDelete,
                    itemGet: itemGet,
                    itemOne: itemOne,
                    itemSkuOne: itemSkuOne,
                    itemAdd: itemAdd,
                    itemUpdate: itemUpdate,
                    oneCacheSet: oneCacheSet,
                    oneCacheDel: oneCacheDel,
                    itemSkuAdd: itemSkuAdd,
                    itemSkuUpdate: itemSkuUpdate,

                    itemDelete: itemDelete,
                    itemStatusUpdate: itemStatusUpdate,
                    disableUpdate: disableUpdate,
                    enableUpdate: enableUpdate,

                    itemSkuStatusUpdate: itemSkuStatusUpdate,
                    orderGet: orderGet,
                    orderOne: orderOne,
                    refundAdd: refundAdd,
                    // orderStatusUpdate: orderStatusUpdate,
                    orderConfirmUpdate: orderConfirmUpdate,
                    orderDeliveryUpdate: orderDeliveryUpdate,
                    orderUpdate: orderUpdate,
                    orderCloseUpdate: orderCloseUpdate,
                    orderCancelUpdate: orderCancelUpdate,
                    returnformAdd: returnformAdd,
                    returnformGet: returnformGet,
                    returnformDelete: returnformDelete,
                    returnformUpdate: returnformUpdate,
                    returnformOne: returnformOne,
                    returnformStatusUpdate: returnformStatusUpdate,
                    cashreqGet: cashreqGet,
                    cashreqAdd: cashreqAdd,
                    cashreqOne: cashreqOne,
                    cashreqUpdate: cashreqUpdate,
                    sellerSuppliersGet: sellerSuppliersGet,
                    sellerSuppliersOne: sellerSuppliersOne,
                    sellercooperationGet: sellercooperationGet,
                    sellercooperationOne: sellercooperationOne,
                    sellercooperationAdd: sellercooperationAdd,
                    sellercooperationUpdate: sellercooperationUpdate,
                    sellercooperationDel: sellercooperationDel,
                    itemSkuTypeAdd: itemSkuTypeAdd,
                    itemSkuTypeGet: itemSkuTypeGet,
                    itemSkuTypeUpdate: itemSkuTypeUpdate,
                    itemSkuTypeDel: itemSkuTypeDel,
                    itemSkuValueAdd: itemSkuValueAdd,
                    itemSkuValueUpdate: itemSkuValueUpdate,
                    itemSkuValueGet: itemSkuValueGet,
                    itemSkuValueDel: itemSkuValueDel,
                    productGet: productGet,
                    productUpdate: productUpdate,
                    webQrcodeGet: webQrcodeGet,
                    wxQrcodeGet: wxQrcodeGet,
                    webTokenGet: webTokenGet,
                    subuserGet: subuserGet,
                    wxappGet: wxappGet,
                    wxappOne: wxappOne,
                    wxappAdd: wxappAdd,
                    wxappUpdate: wxappUpdate,
                    wxappDelete: wxappDelete,
                    shopconfigGet: shopconfigGet,
                    shopConfigAdd: shopConfigAdd,
                    shopConfigUpdate: shopConfigUpdate,
                    shopConfigOne: shopConfigOne,
                    shopConfigOneByKey: shopConfigOneByKey,
                    shopConfigDelete: shopConfigDelete,
                    printPubGet: printPubGet,
                    printPubOne: printPubOne,
                    printPubAdd: printPubAdd,
                    printPubUpdate: printPubUpdate,
                    printPubDelete: printPubDelete,
                    printSellerAdd: printSellerAdd,
                    printSellerUpdate: printSellerUpdate,
                    printSellerDelete: printSellerDelete,
                    printSellerGet: printSellerGet,
                    printSellerOne: printSellerOne,
                    reviewGet: reviewGet,
                    reviewOne: reviewOne,
                    activitypageAdd: activitypageAdd,
                    activitypageGet: activitypageGet,
                    activitypageDel: activitypageDel,
                    activitypageUpdate: activitypageUpdate,
                    activitypageOne: activitypageOne,
                    userappGet: userappGet,
                    userappAdd: userappAdd,
                    userappUpdate: userappUpdate,
                    userappDelete: userappDelete,
                    bindAdd: bindAdd,
                    bindDelete: bindDelete,
                    v1PartnerGet: v1PartnerGet,
                    v1PartnerAdd: v1PartnerAdd,
                    v1PartnerUpdate: v1PartnerUpdate,
                    sellerGet: sellerGet,
                    memberGet: memberGet,
                    memberUpdate: memberUpdate,
                    memberlevelAdd: memberlevelAdd,
                    memberlevelUpdate: memberlevelUpdate,
                    memberlevelGet: memberlevelGet,
                    accountvaleGet: accountvaleGet,
                    basicinfoGet: basicinfoGet,
                    buyerbasicinfoGet: buyerbasicinfoGet,
                    tabletypeAdd: tabletypeAdd,
                    tabletypeGet: tabletypeGet,
                    tabletypeDelete: tabletypeDelete,
                    // tabletypeUpdate: tabletypeUpdate,
                    tableAdd: tableAdd,
                    // tableUpdate: tableUpdate,
                    tableDelete: tableDelete,
                    tableGet: tableGet,
                    periodstlGet: periodstlGet,
                    periodstlAdd: periodstlAdd,
                    groupTimeslotstlAdd: groupTimeslotstlAdd,
                    periodGet: periodGet,
                    periodUpdate: periodUpdate,
                    periodStatusUpdate: periodStatusUpdate,
                    timeslotGet: timeslotGet,
                    timeslotUpdate: timeslotUpdate,
                    reservationGet: reservationGet,

                    periodstlUpdate: periodstlUpdate,
                    timeslotstlGet: timeslotstlGet,
                    timeslotstlAdd: timeslotstlAdd,
                    timeslotstlDelete: timeslotstlDelete,
                    timeslotstlUpdate: timeslotstlUpdate,
                    schematypeAdd: schematypeAdd,
                    schematypeGet: schematypeGet,
                    schematypeDelete: schematypeDelete,
                    schematypeUpdate: schematypeUpdate,
                    schemaGet: schemaGet,
                    schemaAdd: schemaAdd,
                    schemaUpdate: schemaUpdate,
                    schemaDelete: schemaDelete,
                    stltodataAdd: stltodataAdd,
                    balancelogGet: balancelogGet,
                    reserveoptAdd: reserveoptAdd,
                    reserveoptUpdate: reserveoptUpdate,
                    reserveoptGet: reserveoptGet,
                    preorderoptGet: preorderoptGet,
                    preorderAdd: preorderAdd,
                    preorderGet: preorderGet,
                    preordersGet: preordersGet,
                    preorderoptAdd: preorderoptAdd,
                    preoderoptUpdate: preoderoptUpdate,
                    resitemAdd: resitemAdd,
                    resitemGet: resitemGet,
                    resitemDelete: resitemDelete,
                    periodsPublic: periodsPublic,
                    resitemUpdate: resitemUpdate,
                    periodsDelete: periodsDelete,
                    periodsUpdate: periodsUpdate,
                    periodsGet: periodsGet,
                    templatetodataAdd: templatetodataAdd,
                    templateGet: templateGet,
                    templateAdd: templateAdd,
                    templateUpdate: templateUpdate,
                    templateDelete: templateDelete,
                    restypeAdd: restypeAdd,
                    restypeUpdate: restypeUpdate,
                    restypeDelete: restypeDelete,
                    restypeGet: restypeGet,
                    ministoreGet: ministoreGet,
                    ministoreAdd: ministoreAdd,
                    ministoreUpdete: ministoreUpdete,
                    sellerUserCurrentGet: sellerUserCurrentGet,
                    sellerUserUpdate: sellerUserUpdate,
                    /***********王苍 -end*********************/

                    /***********郭 -start*********************/
                    authorizePreAuthCodeGet: authorizePreAuthCodeGet,
                    authorizeAuthCodeGet: authorizeAuthCodeGet,
                    isvLogin: isvLogin,
                    isvWxappOne: isvWxappOne,
                    isvWxappGet: isvWxappGet,
                    custaccountGet: custaccountGet,
                    customsItemsUpdate: customsItemsUpdate,
                    isvWxappAdd: isvWxappAdd,
                    isvWxappUpdate: isvWxappUpdate,
                    isvWxappDelete: isvWxappDelete,
                    serviceUpdate: serviceUpdate,
                    isvCodeCommitAdd: isvCodeCommitAdd,
                    getStoreCodeStatus: getStoreCodeStatus,
                    isvTesterAdd: isvTesterAdd,
                    isvTesterDelete: isvTesterDelete,
                    testerGet: testerGet,
                    isvCodeQrcodeGet: isvCodeQrcodeGet,
                    codeSubmitAuditAdd: codeSubmitAuditAdd,
                    codeAuditStatusGet: codeAuditStatusGet,
                    getLatestAuditStatus: getLatestAuditStatus,

                    codeReleaseAdd: codeReleaseAdd,

                    sellerAuthorizeAuthorizer_infoGet: sellerAuthorizeAuthorizer_infoGet,
                    storeAppAllGet: storeAppAllGet,
                    storeAppAdd: storeAppAdd,
                    storeAppDel: storeAppDel,
                    storeApplistGet: storeApplistGet,
                    wxappAuthorizerOne: wxappAuthorizerOne,
                    sellerCodeGetCategoryGet: sellerCodeGetCategoryGet,
                    sellerCodePageGet: sellerCodePageGet,

                    domainUpdate: domainUpdate,

                    notifyGet: notifyGet,
                    notifyOne: notifyOne,
                    isvNotifyAdd: isvNotifyAdd,
                    isvNotifyUpdate: isvNotifyUpdate,
                    isvNotifyDelete: isvNotifyDelete,

                    uimodsGet: uimodsGet,
                    uimodsOne: uimodsOne,
                    uimodsAdd: uimodsAdd,
                    uimodsUpdate: uimodsUpdate,
                    uimodsDelete: uimodsDelete,

                    resourceGet: resourceGet,
                    resourcesOne: resourcesOne,
                    roleGet: roleGet,
                    roleOne: roleOne,
                    roleDel: roleDel,
                    roleAdd: roleAdd,


                    /***********郭 -end*********************/

                    //打折
                    dazheGet: dazheGet,
                    dazheAdd: dazheAdd,
                    addItemCuxiao: addItemCuxiao,
                    removeItemCuxiao: removeItemCuxiao,
                    dazheUpdate: dazheUpdate,
                    dazheDelete: dazheDelete,
                    actItemGet: actItemGet,


                    //包邮
                    postfeeGet: postfeeGet,
                    postfeeAdd: postfeeAdd,
                    postfeeUpdate: postfeeUpdate,
                    postfeeDelete: postfeeDelete,
                    getProvinceCity: getProvinceCity,

                    //阶梯运费
                    stepfreightGet: stepfreightGet,
                    stepfreightAdd: stepfreightAdd,
                    stepfreightUpdate: stepfreightUpdate,
                    stepfreightDelete: stepfreightDelete,

                    //砍价
                    kanjiaGet: kanjiaGet,
                    kanjiaGetOne: kanjiaGetOne,
                    kanjiaAdd: kanjiaAdd,
                    kanjiaUpdate: kanjiaUpdate,
                    kanjiaDelete: kanjiaDelete,
                    activityget: activityget,
                    ffectget: ffectget,

                    //卡券
                    card: card,
                    cardidGet: cardidGet,
                    cardListGet: cardListGet,
                    cardLogGet: cardLogGet,
                    cardLogUpdate: cardLogUpdate,

                    //批量上传代码
                    batchUpload: batchUpload,
                    batchGet: batchGet,

                    //拼团
                    pintuanGet: pintuanGet,
                    pintuanAdd: pintuanAdd,
                    pintuanUpdate: pintuanUpdate,
                    pintuanDelete: pintuanDelete,

                    pintuanactivityGet: pintuanactivityGet,
                    pintuandetilGet: pintuandetilGet,

                    //充值活动
                    balanceGet: balanceGet,
                    balanceAdd: balanceAdd,
                    balanceUpdate: balanceUpdate,
                    balanceDelete: balanceDelete,

                    //满就送
                    mjsGet: mjsGet,
                    mjsAdd: mjsAdd,
                    mjsUpdate: mjsUpdate,
                    mjsItemGet: mjsItemGet,
                    mjsItemAdd: mjsItemAdd,
                    mjsItemDelete: mjsItemDelete,
                    mjsRangeGet: mjsRangeGet,
                    mjsRangeAdd: mjsRangeAdd,
                    mjsRangeDelete: mjsRangeDelete,
                    // mjsDelete: mjsDelete

                    //分销商品
                    distributorGet: distributorGet,
                    distributorUpdate: distributorUpdate,
                    distributorOrderGet: distributorOrderGet,
                    distributorOrderUpdate: distributorOrderUpdate,
                    distributorClearingOrderGet: distributorClearingOrderGet,
                    distributorClearingDetailGet: distributorClearingDetailGet,
                    distributorClearingOrderUpdate: distributorClearingOrderUpdate,

                    //分销等级
                    fxgradeGet: fxgradeGet,
                    fxgradeAdd: fxgradeAdd,
                    fxgradeUpdate: fxgradeUpdate,

                    //产品线
                    fxproductGet: fxproductGet,
                    fxproductAdd: fxproductAdd,
                    fxproductUpdate: fxproductUpdate,

                    //产品线商品
                    fxproductitemGet: fxproductitemGet,
                    fxproductItemAdd: fxproductItemAdd,
                    fxproductItemDelete: fxproductItemDelete,

                    wxproxy: wxproxy,
                    xcxAppJson: xcxAppJson,

                    //自动回复规则查询
                    autorspcfgGet: autorspcfgGet,
                    autorspcfgUpdate: autorspcfgUpdate,

                    //订单折扣修改
                    discountUpdate: discountUpdate,

                    //报名活动
                    huodongGet: huodongGet,
                    huodongAdd: huodongAdd,
                    huodongUpdate: huodongUpdate,
                    huodongDetailGet: huodongDetailGet,
                    saveSecretKey: saveSecretKey,
                    huodongDetailUpdate: huodongDetailUpdate,

                    //服务
                    fuwuGet: fuwuGet,
                    fuwuAdd: fuwuAdd,
                    fuwuUpdate: fuwuUpdate,
                    fuwuOrderGet: fuwuOrderGet,
                    fuwuOrderAdd: fuwuOrderAdd,
                    fuwuManualOrderAdd: fuwuManualOrderAdd,
                    cancleOrder: cancleOrder,
                    fuwuDetailGet: fuwuDetailGet,
                    fuwuDetailUpdate: fuwuDetailUpdate,
                    fuwuClearingGet: fuwuClearingGet,
                    fuwuClearingUpdate: fuwuClearingUpdate,
                    fuwuClearingDetailGet: fuwuClearingDetailGet,

                    //服务代理订单
                    zhuanqianOrderGet: zhuanqianOrderGet,

                    //服务活动
                    serviceactivityGet: serviceactivityGet,
                    serviceactivityAdd: serviceactivityAdd,
                    serviceactivityUpdate: serviceactivityUpdate,

                    //红包
                    hongbaoGet: hongbaoGet,
                    hongbaoGetOne: hongbaoGetOne,
                    hongbaoAdd: hongbaoAdd,
                    hongbaoUpdate: hongbaoUpdate,
                    hongbaoDetailGet: hongbaoDetailGet,
                    withdrawalLogGet: withdrawalLogGet,

                    //订单附加信息
                    orderExtInfoGet: orderExtInfoGet,

                    sceneSave: sceneSave,
                    sceneGet: sceneGet,
                    adminlayoutAdd: adminlayoutAdd,
                    adminlayoutUpdate: adminlayoutUpdate,
                    adminlayoutGet: adminlayoutGet,
                    adminlayoutDel: adminlayoutDel,
                    adminlayoutOne: adminlayoutOne,
                    userlayoutAdd: userlayoutAdd,
                    userlayoutDel: userlayoutDel,
                    userlayoutGet: userlayoutGet,
                    simutaskGet: simutaskGet,
                    simutaskAdd: simutaskAdd,
                    simutaskGetOne: simutaskGetOne,
                    simutaskDel: simutaskDel,
                    backliuyanAdd: backliuyanAdd,
                    backliuyanGet: backliuyanGet,
                    mianfuAdd: mianfuAdd,
                    mianfuGet: mianfuGet,
                    buyerliuyanAdd: buyerliuyanAdd,
                    nsqRequest: nsqRequest,
                    buyerliuyanGet: buyerliuyanGet,
                    h5hdAdd: h5hdAdd,
                    h5hdGet: h5hdGet,
                    h5hdUpdate: h5hdUpdate,
                    h5hdDel: h5hdDel,
                    h5hddetailGet: h5hddetailGet,
                    h5hddetailUpdate: h5hddetailUpdate,
                    wifiToken: wifiToken,
                    wifiDeviceList: wifiDeviceList,
                    gzhWifiShopList: gzhWifiShopList,
                    gzhWifiShop: gzhWifiShop,
                    gzhWifiDevice: gzhWifiDevice,
                    gzhWifiDeviceDelete: gzhWifiDeviceDelete,
                    gzhWifiDeviceAdd: gzhWifiDeviceAdd,
                    gzhWifiQrcodeGet: gzhWifiQrcodeGet,
                    gzhWifiShopClean: gzhWifiShopClean,
                    gzhUnLinkApp: gzhUnLinkApp,
                    gzhLinkApp: gzhLinkApp,
                    gzhWxopenWxamplink: gzhWxopenWxamplink,
                    gzhWifiHomePageSet: gzhWifiHomePageSet,
                    gzhWifiFinishPageSet: gzhWifiFinishPageSet,
                    gzhWifiBarSet: gzhWifiBarSet,
                    wxUpdateNews: wxUpdateNews,
                    wxSendall: wxSendall,
                    preview: preview,
                    wxDelMaterial: wxDelMaterial,
                    wxAddNews: wxAddNews,
                    WxGettemplatedraftlist: WxGettemplatedraftlist,
                    classAdd: classAdd,
                    classGet: classGet,
                    classUpdate: classUpdate,
                    classdetailGet: classdetailGet,
                    classdetailAdd: classdetailAdd,
                    classdetailUpdate: classdetailUpdate,
                    pickpointGet: pickpointGet,
                    pickpointUpdate: pickpointUpdate,
                    pickpointDelete: pickpointDelete,
                    pickpointStatusUpdate: pickpointStatusUpdate,
                    orderPickpointUpdate: orderPickpointUpdate,

                    luckydrawGet: luckydrawGet,
                    luckydrawAdd: luckydrawAdd,
                    luckydrawUpdate: luckydrawUpdate,
                    drawdetailGet: drawdetailGet,
                    drawdetailAdd: drawdetailAdd,
                    drawpullGet: drawpullGet,

                    classCategoryGet: classCategoryGet,
                    classCategoryAdd: classCategoryAdd,
                    classCategoryUpdate: classCategoryUpdate,

                    roomsGet: roomsGet,
                    roomsAdd: roomsAdd,
                    roomsUpdate: roomsUpdate,
                    roomskusDelete: roomskusDelete,
                    roomstagGet: roomstagGet,
                    roomstagAdd: roomstagAdd,
                    roomsOrderGet: roomsOrderGet,
                    roomsOrderUpdate: roomsOrderUpdate,

                    nsqCommonAdd: nsqCommonAdd,
                    printPOs: printPOs,

                    praiseGet: praiseGet,
                    commentsGet: commentsGet,
                    commentsUpdate: commentsUpdate,
                    manualcommentsAdd: manualcommentsAdd,

                    couponGet: couponGet,
                    couponAdd: couponAdd,
                    couponUpdate: couponUpdate,
                    couponItemGet: couponItemGet,
                    couponItemAdd: couponItemAdd,
                    // subscribeGet: subscribeGet,
                    subscribecacheGet: subscribecacheGet,
                    couponItemDelete: couponItemDelete,
                    //打卡有礼
                    giftAdd: giftAdd,
                    dakaAdd: dakaAdd,
                    giftGet: giftGet,
                    giftOne: giftOne,
                    giftdetailsGet: giftdetailsGet,
                    //表白活动
                    confessionGet: confessionGet,
                    confessionDetailGet: confessionDetailGet,
                    confessionAdd: confessionAdd,
                    confessionUpdate: confessionUpdate,
                    confessionItemGet: confessionItemGet,
                    confessionItemAdd: confessionItemAdd,
                    confessionItemDelete: confessionItemDelete,

                    //企业微信
                    qycorpBindpartner: qycorpBindpartner,
                    qyCorpGet: qyCorpGet,

                    //新增接口调用者
                    openapiuserAdd: openapiuserAdd,
                    //获取微信图片 视频 语音
                    wxMaterialGet: wxMaterialGet,
                    //api机制的api
                    adminUnbind: adminUnbind,
                    giftBaobiao: giftBaobiao,
                    giftDestroy: giftDestroy,
                    wxapptempList: wxapptempList,
                    wxappdeltemplated: wxappdeltemplated,
                    addtotemplate: addtotemplate,
                    mzGet: mzGet,
                    mzDetailGet: mzDetailGet,
                    mzAdd: mzAdd,
                    mzUpdate: mzUpdate,
                    storetongjiPaymentGet: storetongjiPaymentGet,
                    storetongjiWxappanalysiGet: storetongjiWxappanalysiGet,
                    phpResourcesGet: phpResourcesGet,
                    phpResourcesUpdate: phpResourcesUpdate,
                    phpResourcesStatusUpdate: phpResourcesStatusUpdate,
                    //抽奖活动 查询猜中
                    winPeopleGet: winPeopleGet,
                    phpPermissionGet: phpPermissionGet,
                    phpPermissionAdd: phpPermissionAdd,
                    phpPermissionDelete: phpPermissionDelete,

                    //模板消息
                    templateList: templateList,
                    titleLibraryGet: titleLibraryGet,
                    templateTitleListGet: templateTitleListGet,
                    keywordLibraryGet: keywordLibraryGet,
                    keywordGet: keywordGet,
                    templateLibrarySave: templateLibrarySave,
                    templateAddNew: templateAddNew,
                    getAllPrivateTemplate: getAllPrivateTemplate,
                    apiAddTemplate: apiAddTemplate,

                    //听写
                    tingWordsGet: tingWordsGet,
                    tingClassGet: tingClassGet,
                    tingChildGet: tingChildGet,
                    tongjiGet: tongjiGet,
                    tingClassDetailGet: tingClassDetailGet,

                    //发送短信
                    sendMbMsg: sendMbMsg,

                    mbMsgLog: mbMsgLog,
                    sendTemplateMsg: sendTemplateMsg,
                    sendGzhTemplateMsg: sendGzhTemplateMsg,

                    //查询单个授权的小程序信息
                    getCustaccount: getCustaccount,
                    wxCgibinOpenGet: wxCgibinOpenGet,
                    wxCgibinOpenCreate: wxCgibinOpenCreate,
                    addAppPlatform: addAppPlatform,
                    getAppPlatformInfo: getAppPlatformInfo,
                    getPlatformInfo: getPlatformInfo,
                    //复制店铺数据
                    copyStoreData: copyStoreData,
                    copyLayoutData: copyLayoutData,
                    wxCgibinOpenBind: wxCgibinOpenBind,
                    wxCgibinOpenUnbind: wxCgibinOpenUnbind,
                    rmAppPlatform: rmAppPlatform,

                    //php更新会员等级
                    phpMemberlevelUpdate: phpMemberlevelUpdate,
                    wxkfadd: wxkfadd,
                    wxkfget: wxkfget,
                    wxkfdel: wxkfdel,
                    phpWxgzhmemberGet: phpWxgzhmemberGet,
                    redpackAdd: redpackAdd,
                    phpgroupredpack: phpgroupredpack,
                    phpredpack: phpredpack,
                    phpsynchronizationData: phpsynchronizationData,
                    phpsubscribeGet: phpsubscribeGet,
                    phpisvwxappGet: phpisvwxappGet,
                    getlindustrycode: getlindustrycode,
                    deskQrcode: deskQrcode,
                    printerGet: printerGet,
                    printerAdd: printerAdd,
                    printerRemove: printerRemove,
                    printerUpstoreid: printerUpstoreid,
                    msgsetGet: msgsetGet,
                    msgsetAdd: msgsetAdd,
                    printrelationGet: printrelationGet,
                    printrelationAdd: printrelationAdd,
                    printrelationDel: printrelationDel,
                    printerGetpos: printerGetpos,
                    printreAppWork: printreAppWork,
                    carrywayTypeGet: carrywayTypeGet,
                    //设置中奖人员
                    setWin: setWin,
                    //商品标签
                    labelAdd: labelAdd,
                    labelGet: labelGet,
                    labelDel: labelDel,
                    //仓库
                    wmsAdd: wmsAdd,
                    wmsGet: wmsGet,
                    wmsDel: wmsDel,
                    websiteAdd: websiteAdd,
                    websiteGet: websiteGet,
                    customsItemsGet: customsItemsGet,
                    getCustomsnotifys: getCustomsnotifys,
                    wmsBinding: wmsBinding,

                    itemLabelRelationAdd: itemLabelRelationAdd,
                    itemLabelRelationGet: itemLabelRelationGet,
                    itemlabelrelationDel: itemlabelrelationDel,
                    catLabelRelationAdd: catLabelRelationAdd,
                    catLabelRelationGet: catLabelRelationGet,
                    catlabelrelationDel: catlabelrelationDel,
                    wxTagsCreate: wxTagsCreate,
                    wxTagsGet: wxTagsGet,
                    wxTagsUpdate: wxTagsUpdate,
                    wxmenuGet: wxmenuGet,
                    wxCurrentSelfmenuGet: wxCurrentSelfmenuGet,
                    wxCurrentSelfmenuCreate: wxCurrentSelfmenuCreate,
                    getUserSteps: getUserSteps,
                    //自定义表单
                    customformGet: customformGet,
                    customformAdd: customformAdd,
                    customformTypeGet: customformTypeGet,
                    customformTypeAdd: customformTypeAdd,
                    formGet: formGet,
                    formAdd: formAdd,
                    formDataGet: formDataGet,
                    formDataAdd: formDataAdd,
                    formDataUpdate: formDataUpdate,
                    postPay: postPay,
                    postOrder: postOrder,
                    postItemWms: postItemWms,
                    postOederWms: postOederWms,
                    batchDeliverGoods: batchDeliverGoods,
                    getAllCity: getAllCity,

                    customsOrderGet: customsOrderGet,
                    customsConfigGet: customsConfigGet,
                    customsConfigOne: customsConfigOne,
                    customsConfigAdd: customsConfigAdd,
                    customsConfigDel: customsConfigDel,
                    customsSyncOrder: customsSyncOrder,
                    customsUpdataPickPoint: customsUpdataPickPoint,
                    chatRecordGet: chatRecordGet,
                    addStoredistribution: addStoredistribution,
                    getStoredistribution: getStoredistribution,
                    getFzitems: getFzitems,
                    addItemsdistribution: addItemsdistribution,
                    getStoredistributionGroup: getStoredistributionGroup,
                    getStoredistributionAdd: getStoredistributionAdd,
                    getItemUnCode: getItemUnCode,
                    getfzlog: getfzlog,
                    deleteMember: deleteMember,
                    deliveryGet: deliveryGet,
                    deliveryConfigGet: deliveryConfigGet,
                    deliveryConfigAdd: deliveryConfigAdd,
                    businessOrderAdd: businessOrderAdd,
                    wxservicetype: wxservicetype,
                    getCustomsCode: getCustomsCode,
                    getPortCode: getPortCode,
                    downloaditemsGet: downloaditemsGet,
                    savemainstoreitem: savemainstoreitem,
                    savesubstoreitem: savesubstoreitem,
                    Refund: Refund,
                    sku2skusAdd: sku2skusAdd,
                    virtualSkuGet: virtualSkuGet,
                    sku2skusDelete: sku2skusDelete,
                    manualClearingOrderUpdate: manualClearingOrderUpdate,
                    implementfz: implementfz,
                    fzFinish: fzFinish,
                    manualOrderAdd: manualOrderAdd,
                    getfz: getfz,
                    quickorderList: quickorderList,
                    delQuickOrder: delQuickOrder,
                    delVirtual: delVirtual,
                    gettemtax: gettemtax,
                    getmainskuprice: getmainskuprice,
                    getskulist: getskulist,
                    // confirmYuou:confirmYuou,
                    // yorder:yorder
                    lackpaybill: lackpaybill,
                    // yuouWuliu:yuouWuliu,
                    // confirmWuliu:confirmWuliu,
                    getFreezeLog: getFreezeLog,
                    distributorPayDirectly: distributorPayDirectly,
                    getdtb: getdtb,
                    tbSceneSave: tbSceneSave,
                    updatedIdcard: updatedIdcard,
                    zuofei: zuofei,
                    pushWmsMsg: pushWmsMsg,
                    pushClearOrder: pushClearOrder,
                    delItem: delItem,
                    exportcsv: exportcsv,
                    isfile: isfile,
                    subscribemessageGet: subscribemessageGet,
                    addTemplateToPersonal: addTemplateToPersonal,
                    mySubscribemessageGet: mySubscribemessageGet,
                    delTemplate: delTemplate,
                    NewPaySeparate: NewPaySeparate,
                    topauth: topauth,
                    getCountryCode: getCountryCode,
                    upOrderFlag: upOrderFlag
                };
                return dataService;
                /********************************************************************
                //api2机制的api都在这里      ----开始--------
                ********************************************************************/
                //订单打标
                function upOrderFlag(data) {
                    return requestApi2("dhf.order.upflag", data).then(function(result) {
                        return result;
                    });
                }

                //查询商品原产国单位代码
                function getCountryCode() {
                    return requestApi2("dhf.wms.getcountrycode", null, 3600 * 24 * 30).then(function(result) {
                        return result;
                    });
                }

                function delTemplate(data) {
                    return requestApi2("dhf.template.deltemplate", data).then(function(result) {
                        return result;
                    });
                }

                function mySubscribemessageGet(data) {
                    return requestApi2("dhf.template.mysubscribemessageget", data).then(function(result) {
                        return result;
                    });
                }

                function addTemplateToPersonal(data) {
                    return requestApi2("dhf.template.addtemplatetopersonal", data).then(function(result) {
                        return result;
                    });
                }

                function subscribemessageGet(data) {
                    return requestApi2("dhf.template.subscribemessageget", data).then(function(result) {
                        return result;
                    });
                }

                //新生支付分账结
                function NewPaySeparate(data) {
                    return requestApi2("dhf.fz.separate", data).then(function(result) {
                        return result;
                    });
                }

                //检测文件是否存在
                function isfile(data, method) {
                    return requestApi2(method, data).then(function(result) {
                        return result;
                    });
                }

                //导出文件worker
                function exportcsv(data, method) {
                    return requestApi2(method, data).then(function(result) {
                        return result;
                    });
                }

                //删除商品
                function delItem(data) {
                    return requestApi2("dhf.item.delitem", data).then(function(result) {
                        return result;
                    });
                }

                //通知仓库拦截订单
                function pushWmsMsg(data) {
                    return requestApi2("dhf.order.wmscancelorder", data).then(function(result) {
                        return result;
                    });
                }

                //补推清单
                function pushClearOrder(data) {
                    return requestApi2("dhf.order.pushclearorder", data).then(function(result) {
                        return result;
                    });
                }

                //订单作废
                function zuofei(data) {
                    return requestApi2("dhf.customsorder.zuofei", data).then(function(result) {
                        return result;
                    });
                }

                //更新收货人信息
                function updatedIdcard(data) {
                    return requestApi2("dhf.customsorder.updateidcard", data).then(function(result) {
                        return result;
                    });
                }

                function tbSceneSave(key, value) {
                    var data = {};
                    data.content = {
                        "skey": key,
                        "svalue": value
                    };
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.scene.save";
                    console.error("scene保存", data);
                    return requestApi("/rest/v1/php/dhf/scene/save", data).then(function(result) {
                        return result;
                    });
                }

                // 
                function distributorPayDirectly(data) {
                    return requestApi2("dhf.fenxiao.paydirectly", data).then(function(result) {
                        return result;
                    });
                }

                //获取大头笔
                function getdtb(order_id) {
                    return requestApi2("dhf.order.getdtb", {
                        order_id: order_id
                    }).then(function(result) {
                        return result;
                    });
                }

                // function yorder(partner_id,store_id, type) {
                //     return requestApi2("dhf.yuouapi.pullorder",{partner_id:partner_id,store_id:store_id,type:type}).then(function(result) {
                //         return result;
                //     });
                // }

                // //渝欧物流确认
                // function confirmWuliu(data) {
                //     return requestApi2("dhf.yuouapi.reportlogistics",data).then(function(result) {
                //         return result;
                //     });
                // }
                //
                // //渝欧物流获取
                // function yuouWuliu(data,ttl) {
                // // ,ttl?ttl:3600
                //     return requestApi2("dhf.yuouapi.getyuougetyulogistics", data).then(function(result) {
                //         return result;
                //     });
                // }

                // //渝欧确认订单
                // function confirmYuou(data) {
                //     return requestApi2("dhf.yuouapi.confirmorder", data).then(function(result) {
                //         return result;
                //     });
                // }

                function applyupdate(data) {
                    console.error("1222", data);
                    return requestApi2("dhf.store.applyupdate", data).then(function(result) {
                        return result;
                    });
                }

                function applyList(data) {
                    return requestApi2("dhf.store.applyget", data).then(function(result) {
                        return result;
                    });
                }

                //渝欧补缺支付单
                function lackpaybill(data) {
                    return requestApi2("dhf.yuouapi.lackpaybill", data).then(function(result) {
                        return result;
                    });
                }

                //查询商品价格
                function getFreezeLog(data) {
                    return requestApi2("dhf.fz.getfreezelog", data).then(function(result) {
                        return result;
                    });
                }
                //查询商品价格
                function getmainskuprice(data) {
                    return requestApi2("dhf.item.getmainskuprice", data).then(function(result) {
                        return result;
                    });
                }
                //查询商品税费
                function gettemtax(data) {
                    return requestApi2("dhf.item.gettemtax", data).then(function(result) {
                        return result;
                    });
                }
                //删除组合商品
                function delVirtual(data) {
                    return requestApi2("dhf.item.delvirtual", data).then(function(result) {
                        return result;
                    });
                }

                //删除快速订单
                function delQuickOrder(data) {
                    return requestApi2("dhf.quickorder.delete", data).then(function(result) {
                        return result;
                    });
                }

                //快速订单
                function quickorderList(data) {
                    return requestApi2("dhf.quickorder.list", data).then(function(result) {
                        return result;
                    });
                }

                //查询sku组合列表
                function getskulist(data, ttl) {
                    return requestApi2("dhf.item.getskulist", data, ttl ? ttl : 3600).then(function(result) {
                        return result;
                    });
                }

                //添加手工订单
                function manualOrderAdd(data) {
                    return requestApi2("dhf.quickorder.manualorderadd", data).then(function(result) {
                        return result;
                    });
                }

                //完结分账
                function fzFinish(data) {
                    return requestApi2("dhf.fz.fzfinish", data).then(function(result) {
                        return result;
                    });
                }

                //分账查询 getfz
                function getfz(data) {
                    return requestApi2("dhf.fz.getfz", data).then(function(result) {
                        return result;
                    });
                }
                //执行分账
                function implementfz(data) {
                    return requestApi2("dhf.fz.implementfz", data).then(function(result) {
                        return result;
                    });
                }

                //手工支付代理佣金
                function manualClearingOrderUpdate(data) {
                    return requestApi2("dhf.fenxiao.manualorderupdate", data).then(function(result) {
                        return result;
                    });
                }

                //虚拟商品列表
                function virtualSkuGet(query) {
                    return requestApi2("dhf.item.virtualget", query).then(function(result) {
                        return result;
                    });
                }

                //sku2skus 删除
                function sku2skusDelete(data) {
                    return requestApi2("dhf.item.virtualitemdelete", data).then(function(result) {
                        return result;
                    });
                }

                //sku2skus
                function sku2skusAdd(sku2skusData) {
                    return requestApi2("dhf.item.sku2skusadd", sku2skusData).then(function(result) {
                        return result;
                    });
                }

                function Refund(data) {
                    return requestApi2("dhf.order.refund", data).then(function(result) {
                        return result;
                    });
                }

                function downloaditemsGet(data) {
                    return requestApi2("dhf.item.getmainstoreitem", data).then(function(result) {
                        return result;
                    });
                }

                function savesubstoreitem(data) {
                    return requestApi2("dhf.item.savesubstoreitem", data).then(function(result) {
                        return result;
                    });
                }

                function savemainstoreitem(data) {
                    return requestApi2("dhf.item.savemainstoreitem", data).then(function(result) {
                        return result;
                    });
                }

                function getCustomsCode(data, ttl) {
                    return requestApi2("dhf.wms.getcustomscode", data, ttl ? ttl : 3600).then(function(result) {
                        return result;
                    });
                }

                function getPortCode(data, ttl) {
                    return requestApi2("dhf.wms.getportcode", data, ttl ? ttl : 3600).then(function(result) {
                        return result;
                    });
                }

                function wxservicetype(data) {
                    return requestApi2("dhf.order.wxservicetype", data).then(function(result) {
                        return result;
                    });
                }

                function businessOrderAdd(data) {
                    return requestApi2("dhf.order.businessorderadd", data).then(function(result) {
                        return result;
                    });
                }

                function deliveryConfigGet(data) {
                    return requestApi2("dhf.order.deliveryconfigget", data).then(function(result) {
                        return result;
                    });
                }

                function deliveryConfigAdd(data) {
                    return requestApi2("dhf.order.deliveryconfigadd", data).then(function(result) {
                        return result;
                    });
                }

                function deliveryGet(data) {
                    return requestApi2("dhf.order.deliverygetall", data).then(function(result) {
                        return result;
                    });
                }

                function deleteMember(data) {
                    return requestApi2("dhf.member.delmemberdata", data).then(function(result) {
                        return result;
                    });
                }
                //查询商品规格单位代码
                function getItemUnCode() {
                    return requestApi2("dhf.wms.getitemunicode", null, 3600 * 24 * 30).then(function(result) {
                        return result;
                    });
                }

                //添加店铺分账
                function addStoredistribution(data) {
                    return requestApi2("dhf.fz.addstore", data).then(function(result) {
                        return result;
                    });
                }
                //分账
                function getfzlog(data) {
                    return requestApi2("dhf.fz.getlog", data).then(function(result) {
                        return result;
                    });
                }
                //添加商品
                function addItemsdistribution(data) {
                    return requestApi2("dhf.fz.additems", data).then(function(result) {
                        return result;
                    });
                }
                //查询分组
                function getStoredistributionGroup(data) {
                    return requestApi2("dhf.fz.getgroups", data).then(function(result) {
                        return result;
                    });
                }
                //添加分组
                function getStoredistributionAdd(data) {
                    return requestApi2("dhf.fz.addgroups", data).then(function(result) {
                        return result;
                    });
                }
                //添加店铺分账
                function getStoredistribution(data) {
                    return requestApi2("dhf.fz.getstore", data).then(function(result) {
                        return result;
                    });
                }

                function getFzitems(data) {
                    return requestApi2("dhf.fz.getfzitems", data).then(function(result) {
                        return result;
                    });
                }

                function customsOrderGet(data) {
                    return requestApi2("dhf.customsorder.get", data).then(function(result) {
                        return result;
                    });
                }

                function customsConfigOne(xid, store_id) {
                    return customsConfigGet({
                        customs_config_id: xid,
                        store_id: store_id
                    }).then(function(result) {
                        if (result && result.total_count == 1) {
                            return result.config_list[0];
                        }
                    });
                }

                function customsConfigGet(data) {
                    return requestApi2("dhf.customsorder.config", data).then(function(result) {
                        if (result && result.total_count) {
                            _.map(result.config_list, function(a) {
                                a.config = JSON.parse(a.config);
                            });
                        }
                        return result;
                    });
                }

                function customsConfigAdd(data) {
                    return requestApi2("dhf.customsorder.configadd", data).then(function(result) {
                        return result;
                    });
                }

                function customsConfigDel(xid, store_id) {
                    return requestApi2("dhf.customsorder.configdel", {
                        customs_config_id: xid,
                        store_id: store_id
                    }).then(function(result) {
                        return result;
                    });
                }

                function batchDeliverGoods(data) {
                    return requestApi2("dhf.order.batchdelivergoods", data).then(function(result) {
                        return result;
                    });
                }

                function customsSyncOrder(store_id) {
                    return requestApi2("dhf.customsorder.syncorder", {
                        store_id: store_id,
                    }).then(function(result) {
                        return result;
                    });
                }

                function customsUpdataPickPoint(order_id, pickpoint_id) {
                    return requestApi2("dhf.customsorder.updatepickpoint", {
                        order_id: order_id,
                        pickpoint_id: pickpoint_id
                    }).then(function(result) {
                        return result;
                    });
                }

                function postPay(id, order_from) {
                    var data = {
                        order_id: id,
                        order_from: order_from
                    };
                    return requestApi2("dhf.order.postpayment", data).then(function(result) {
                        return result;
                    });
                }

                function postOrder(id, type, order_from) {
                    var data = {
                        order_id: id,
                        type: type
                    };
                    if (order_from) {
                        data.order_from = order_from;
                    }
                    return requestApi2("dhf.order.postorder", data).then(function(result) {
                        return result;
                    });
                }
                //推送订单到仓库
                function postOederWms(id) {
                    var data = {
                        order_id: id
                    };
                    return requestApi2("dhf.wms.postorderwms", data).then(function(result) {
                        return result;
                    });
                }

                function postItemWms(id) {
                    var data = {
                        item_id: id
                    };
                    return requestApi2("dhf.wms.postitemwms", data).then(function(result) {
                        return result;
                    });
                }

                function getUserSteps(data) {
                    return requestApi2("dhf.admin.usersteps", data).then(function(result) {
                        return result;
                    });
                }

                //自定义表单
                function customformGet(data) {
                    return requestApi2("dhf.customform.get", data).then(function(result) {
                        return result;
                    });
                }
                //自定义表单添加
                function customformAdd(data) {
                    return requestApi2("dhf.customform.add", data).then(function(result) {
                        return result;
                    });
                }
                //表单选项
                function customformTypeGet(data) {
                    return requestApi2("dhf.customform.typeget", data).then(function(result) {
                        return result;
                    });
                }
                //表单选项添加
                function customformTypeAdd(data) {
                    return requestApi2("dhf.customform.typeadd", data).then(function(result) {
                        return result;
                    });
                }
                //表单字段获取
                function formGet(data) {
                    return requestApi2("dhf.customform.formget", data).then(function(result) {
                        return result;
                    });
                }
                //添加
                function formAdd(data) {
                    return requestApi2("dhf.customform.formadd", data).then(function(result) {
                        return result;
                    });
                }
                //表单数据
                function formDataGet(data) {
                    return requestApi2("dhf.customform.formdataget", data).then(function(result) {
                        return result;
                    });
                }
                //表单数据添加
                function formDataAdd(data) {
                    return requestApi2("dhf.customform.formdataadd", data).then(function(result) {
                        return result;
                    });
                }

                //表单数据修改
                function formDataUpdate(data) {
                    return requestApi2("dhf.customform.formdataupdate", data).then(function(result) {
                        return result;
                    });
                }

                //手工增加评价
                function manualcommentsAdd(data) {
                    return requestApi2("dhf.item.commentsupdate", data).then(function(result) {
                        return result;
                    });
                }
                //自定义菜单
                function wxmenuGet(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function wxCurrentSelfmenuCreate(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function wxCurrentSelfmenuGet(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=TOKEN", "GET", data).then(function(result) {
                        return result;
                    });
                }
                //绑定
                function wxTagsCreate(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/tags/create?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function wxTagsUpdate(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/tags/update?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function wxTagsGet(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function catLabelRelationAdd(data) {
                    return requestApi2("dhf.itemlabel.addcatrelation", data).then(function(result) {
                        return result;
                    });
                }

                function catLabelRelationAdd(data) {
                    return requestApi2("dhf.itemlabel.addcatrelation", data).then(function(result) {
                        return result;
                    });
                }

                function catLabelRelationGet(data) {
                    return requestApi2("dhf.itemlabel.getcatrelation", data).then(function(result) {
                        return result;
                    });
                }

                function catlabelrelationDel(data) {
                    return requestApi2("dhf.itemlabel.delcatrelation", data).then(function(result) {
                        return result;
                    });
                }

                function itemLabelRelationAdd(data) {
                    return requestApi2("dhf.itemlabel.addrelation", data).then(function(result) {
                        return result;
                    });
                }

                function itemLabelRelationGet(data) {
                    return requestApi2("dhf.itemlabel.getrelation", data).then(function(result) {
                        return result;
                    });
                }

                function itemlabelrelationDel(data) {
                    return requestApi2("dhf.itemlabel.delrelation", data).then(function(result) {
                        return result;
                    });
                }
                //查询店铺类型
                function getlindustrycode() {
                    return requestApi2("dhf.storeapp.getlindustrycode").then(function(result) {
                        return result;
                    });
                }


                //仓库
                function wmsAdd(data) {
                    if ($rootScope.is_main == 2 && data.p_wms_id) {
                        helper.myAlert("仓库只能主店修改！");
                        return reject();
                    }
                    return requestApi2("dhf.wms.add", data).then(function(result) {
                        return result;
                    });
                }

                function websiteAdd(data) {
                    return requestApi2("dhf.website.add", data).then(function(result) {
                        return result;
                    });
                }

                function websiteGet(data) {
                    return requestApi2("dhf.website.get", data).then(function(result) {
                        return result;
                    });
                }

                //仓库
                function wmsDel(data) {
                    return requestApi2("dhf.wms.del", data).then(function(result) {
                        return result;
                    });
                }

                function customsItemsGet(data, ttl) {
                    return requestApi2("dhf.item.customsitems", data, ttl ? ttl : 0).then(function(result) {
                        return result;
                    });
                }

                function getCustomsnotifys(data, ttl) {
                    return requestApi2("dhf.order.customsnotify", data, (ttl === 0 || ttl > 0) ? ttl : 300).then(function(result) {
                        return result;
                    });
                }
                //修改海关商品备案信息
                function customsItemsUpdate(data) {
                    return requestApi2("dhf.item.customsitemsupdate", data).then(function(result) {
                        return result;
                    });
                }
                //仓库
                function wmsGet(data, ttl) {
                    return requestApi2("dhf.wms.get", data, ttl ? ttl : 0).then(function(result) {
                        return result;
                    });
                }
                //仓库
                function wmsBinding(data) {
                    return requestApi2("dhf.wms.binding", data).then(function(result) {
                        return result;
                    });
                }

                //商品标签
                function labelAdd(data) {
                    return requestApi2("dhf.itemlabel.add", data).then(function(result) {
                        return result;
                    });
                }

                //商品标签
                function labelDel(data) {
                    return requestApi2("dhf.itemlabel.remove", data).then(function(result) {
                        return result;
                    });
                }

                function labelGet(data) {
                    return requestApi2("dhf.itemlabel.get", data).then(function(result) {
                        return result;
                    });
                }
                //设置中奖人员
                function setWin(data) {
                    return requestApi2("dhf.luckydraw.setwin", data).then(function(result) {
                        return result;
                    });
                }
                //查询绑定的打印机模板
                function printrelationGet(data) {
                    return requestApi2("dhf.print.relationget", data).then(function(result) {
                        return result;
                    });
                }
                //查询绑物流公司
                function carrywayTypeGet(data) {
                    return requestApi2("dhf.print.getlogistics", data).then(function(result) {
                        return result;
                    });
                }
                //推送打印消息
                function printreAppWork(data) {
                    return requestApi2("dhf.print.appwork", data).then(function(result) {
                        return result;
                    });
                }
                //查询绑定的打印机模板
                function printerGetpos(data) {
                    return requestApi2("dhf.print.getpos", data).then(function(result) {
                        return result;
                    });
                }
                //添加 关联
                function printrelationAdd(data) {
                    return requestApi2("dhf.print.relationadd", data).then(function(result) {
                        return result;
                    });
                }
                //shas删除关联
                function printrelationDel(data) {
                    return requestApi2("dhf.print.relationdel", data).then(function(result) {
                        return result;
                    });
                }
                //配置是否发送消息
                function msgsetAdd(data) {
                    return requestApi2("dhf.msgset.add", data).then(function(result) {
                        return result;
                    });
                }

                function msgsetGet(data) {
                    return requestApi2("dhf.msgset.get", data).then(function(result) {
                        return result;
                    });
                }
                //查询打印机
                function printerGet(data) {
                    return requestApi2("dhf.printer.get", data).then(function(result) {
                        return result;
                    });
                }
                //修改
                function printerUpstoreid(data) {
                    return requestApi2("dhf.printer.upstoreid", data).then(function(result) {
                        return result;
                    });
                }

                function printerAdd(data) {
                    return requestApi2("dhf.printer.add", data).then(function(result) {
                        return result;
                    });
                }

                function printerRemove(data) {
                    return requestApi2("dhf.printer.remove", data).then(function(result) {
                        return result;
                    });
                }
                //生成餐桌二维码
                function deskQrcode(data) {
                    return requestApi2("dhf.desk.deskqrcode", data).then(function(result) {
                        return result;
                    });
                }

                //查询是否关注公众号
                function phpsubscribeGet(data) {
                    return requestApi2("dhf.wxgzhmember.subscribeget", data).then(function(result) {
                        return result;
                    });
                }

                //查询公共的小程序  
                function phpisvwxappGet(data) {
                    return requestApi2("dhf.storeapp.isvwxappget", data).then(function(result) {
                        return result;
                    });
                }



                //同步数据
                function phpsynchronizationData(data) {
                    return requestApi2("dhf.wxgzhmember.synchronizationdata", data).then(function(result) {
                        return result;
                    });
                }

                //发放普通红包
                function redpackAdd(data) {
                    return requestApi("/rest/rpc/mmpaymkttransfers/redpack/add", data).then(function(result) {
                        return result;
                    });
                }

                //发送红包
                function phpredpack(data) {
                    return requestApi2("dhf.wxgzhmember.redpack", data).then(function(result) {
                        return result;
                    });
                }
                //发送红包
                function phpgroupredpack(data) {
                    return requestApi2("dhf.wxgzhmember.groupredpack", data).then(function(result) {
                        return result;
                    });
                }
                //获取公众号会员
                function phpWxgzhmemberGet(data) {
                    return requestApi2("dhf.wxgzhmember.get", data).then(function(result) {
                        return result;
                    });
                }

                function phpMemberlevelUpdate(data) {
                    return requestApi2("dhf.member.levelupdate", data).then(function(result) {
                        return result;
                    });
                }

                function wxkfdel(data) {
                    return requestApi2("dhf.wxkf.del", data).then(function(result) {
                        return result;
                    });
                }


                function wxkfadd(data) {
                    return requestApi2("dhf.wxkf.add", data).then(function(result) {
                        return result;
                    });
                }

                function wxkfget(data) {
                    return requestApi2("dhf.wxkf.get", data).then(function(result) {
                        return result;
                    });
                }

                function addAppPlatform(data) {
                    return requestApi2("dhf.wxplatform.addappplatform", data).then(function(result) {
                        return result;
                    });
                }

                function rmAppPlatform(data) {
                    return requestApi2("dhf.wxplatform.rmappplatform", data).then(function(result) {
                        return result;
                    });
                }
                //解除绑定
                function wxCgibinOpenUnbind(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/open/unbind?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }

                function getPlatformInfo(data) {
                    return requestApi2("dhf.wxplatform.getplatforminfo", data).then(function(result) {
                        return result;
                    });
                }

                function getAppPlatformInfo(data) {
                    return requestApi2("dhf.wxplatform.getappplatforminfo", data).then(function(result) {
                        return result;
                    });
                }

                //绑定关系
                function wxCgibinOpenBind(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/open/bind?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }
                //复制装修数据
                function copyLayoutData(data) {
                    return requestApi2("dhf.copy.copylayoutdata", data).then(function(result) {
                        return result;
                    });
                }

                //复制店铺数据
                function copyStoreData(data) {
                    return requestApi2("dhf.copy.copystoredata", data).then(function(result) {
                        return result;
                    });
                }

                function getmaxcount(data) {
                    return requestApi2("dhf.mbmsg.getmaxcount", data).then(function(result) {
                        return result;
                    });
                }

                //发送短信
                function sendMbMsg(data) {
                    return requestApi2("dhf.mbmsg.send", data).then(function(result) {
                        return result;
                    });
                }


                function mbMsgLog(data) {
                    return requestApi2("dhf.mbmsg.log", data).then(function(result) {
                        return result;
                    });
                }

                //发送消息
                function sendTemplateMsg(data) {
                    return requestApi2("dhf.mbmsg.sendtemplate", data).then(function(result) {
                        return result;
                    });
                }

                //发送公众号模板消息
                function sendGzhTemplateMsg(data) {
                    return requestApi2("dhf.mbmsg.sendgzhtemplate", data).then(function(result) {
                        return result;
                    });
                }

                function tingWordsGet(data) {
                    return requestApi2("dhf.ting.wordget", data).then(function(result) {
                        return result;
                    });
                }
                // tongjipaymenGet
                function tongjiGet(data) {
                    return requestApi2("dhf.storetongji.getpaymentredis", data).then(function(result) {
                        return result;
                    });
                }

                function tingClassDetailGet(data) {
                    return requestApi2("dhf.ting.classdetailsget", data).then(function(result) {
                        return result;
                    });
                }

                function tingClassGet(data) {
                    return requestApi2("dhf.ting.classget", data).then(function(result) {
                        return result;
                    });
                }

                function tingChildGet(data) {
                    return requestApi2("dhf.ting.childget", data).then(function(result) {
                        return result;
                    });
                }

                function winPeopleGet(draw_id, win_number) {
                    var data = {
                        store_id: $rootScope.store_id,
                        draw_id: draw_id,
                        win_number: win_number,
                    };
                    return requestApi2("dhf.luckydraw.winpeople", data).then(function(result) {
                        return result;
                    });
                }

                function addtotemplate(draft_id) {
                    var data = {
                        draft_id: draft_id,
                    };
                    return requestApi2("dhf.admin.addtotemplate", data).then(function(result) {
                        return result;
                    });
                }
                //查询小程序代码模板列表
                function wxapptempList(type, id) {
                    var data = {
                        type: type,
                    };
                    if (id) {
                        data.id = id;
                    }
                    return requestApi2("dhf.admin.gettemplatedlist", data).then(function(result) {
                        return result;
                    });
                }

                function wxappdeltemplated(id) {
                    var data = {
                        id: id,
                    };
                    return requestApi2("dhf.admin.deltemplated", data).then(function(result) {
                        return result;
                    });
                }

                //查询
                function storetongjiPaymentGet(time, store_id) {
                    var data = {
                        store_id: store_id ? store_id : $rootScope.store_id,
                        time: time,
                    };
                    return requestApi2("dhf.storetongji.payment", data).then(function(result) {
                        return result;
                    });
                }
                //查询
                function storetongjiWxappanalysiGet(appid) {
                    var data = {
                        app_id: appid,
                    };
                    return requestApi2("dhf.storetongji.wxappanalysi", data).then(function(result) {
                        return result;
                    });
                }

                //PHP资源列表
                function phpResourcesGet(data, ttl) {
                    var ttl = _.isNumber(ttl) ? ttl : 0;

                    return requestApi2("dhf.phpresources.get", data).then(function(result) {
                        return result;
                    });
                }
                //创建 微信平台
                function wxCgibinOpenCreate(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/open/create?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }
                //获取小程序/公众号是否设置微信开放平台帐号
                function wxCgibinOpenGet(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/open/get?access_token=TOKEN", "POST", data).then(function(result) {
                        return result;
                    });
                }
                //更新
                function phpResourcesUpdate(data) {
                    return requestApi2("dhf.phpresources.update", data).then(function(result) {
                        return result;
                    });
                }

                //更新状态
                function phpResourcesStatusUpdate(data) {
                    return requestApi2("dhf.phpresources.statusupdate", data).then(function(result) {
                        return result;
                    });
                }

                //附加资源
                function phpPermissionGet(data) {
                    return requestApi2("dhf.phpresources.permissionget", data).then(function(result) {
                        return result;
                    });
                }

                //附加资源
                function phpPermissionAdd(data) {
                    return requestApi2("dhf.phpresources.permissionadd", data).then(function(result) {
                        return result;
                    });
                }

                //附加资源删除
                function phpPermissionDelete(data) {
                    return requestApi2("dhf.phpresources.permissiondelete", data).then(function(result) {
                        return result;
                    });
                }

                /*
                 * 模板消息
                 */
                //存储模板库列表
                function templateList(data) {
                    return requestApi2("dhf.template.list", data).then(function(result) {
                        return result;
                    });
                }
                //标题库
                function titleLibraryGet(data) {
                    return requestApi2("dhf.template.titlelibrary", data).then(function(result) {
                        return result;
                    });
                }

                function templateTitleListGet(data) {
                    return requestApi2("dhf.template.titlelist", data).then(function(result) {
                        return result;
                    });
                }

                //关键词库
                function keywordLibraryGet(data) {
                    return requestApi2("dhf.template.keywordlibrary", data).then(function(result) {
                        return result;
                    });
                }

                function keywordGet(data) {
                    return requestApi2("dhf.template.keywordget", data).then(function(result) {
                        return result;
                    });
                }


                //模板库存储
                function templateLibrarySave(data) {
                    return requestApi2("dhf.template.templatesave", data).then(function(result) {
                        return result;
                    });
                }

                function templateAddNew(data) {
                    return requestApi2("dhf.template.templateadd", data).then(function(result) {
                        return result;
                    });
                }

                //公众号模板消息
                function getAllPrivateTemplate(data) {
                    return requestApi2("dhf.template.download", data).then(function(result) {
                        return result;
                    });
                }

                //添加模板
                function apiAddTemplate(data) {
                    return requestApi2("dhf.template.addtemplate", data).then(function(result) {
                        return result;
                    });
                }


                //打卡礼物核销 
                function giftDestroy(gift_d_id) {
                    var data = {
                        gift_d_id: gift_d_id
                    };
                    return requestApi2("dhf.gift.destroy", data).then(function(result) {
                        return result;
                    });
                }

                //满赠列表
                function mzGet(data) {
                    return requestApi2("dhf.mz.get", data).then(function(result) {
                        return result;
                    });
                }

                //满赠详情列表
                function mzDetailGet(data) {
                    return requestApi2("dhf.mz.detail", data).then(function(result) {
                        return result;
                    });
                }

                //满赠添加
                function mzAdd(data) {
                    var xdata = mzData(data);
                    var content = xdata;

                    return requestApi2("dhf.mz.add", content).then(function(result) {
                        return result;
                    });
                }

                //满赠更新
                function mzUpdate(data) {
                    var xdata = mzData(data);
                    var content = xdata;

                    return requestApi2("dhf.mz.add", content).then(function(result) {
                        return result;
                    });
                }

                function mzData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return angular.toJson(xdata);
                }

                function adminUnbind(wxId) {
                    var content = {
                        wxId: wxId,
                    };

                    return requestApi2("dhf.admin.unbind", content).then(function(result) {
                        return result;
                    });
                }

                function giftBaobiao(gift_id, start_time, end_time) {
                    var content = {
                        gift_id: gift_id,
                    };
                    if (start_time) {
                        content.start_time = toStdTime(start_time);
                    }
                    if (end_time) {
                        content.end_time = toStdTime(end_time);
                    }
                    return requestApi2("dhf.gift.baobiao", content).then(function(result) {
                        return result;
                    });
                }

                function requestApi2(method, content, ttl, reqMethod) {
                    var data = {};
                    data.method = method;
                    if (content) {
                        data.content = angular.toJson(content);
                    }
                    return requestApi("php", data, ttl, reqMethod)
                }
                /********************************************************************
                 //api2机制的api都在这里      ----结束--------
                 ********************************************************************/
                function topauth(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/topauth/update", xdata).then(function(result) {
                        return result;
                    });
                }

                function wxMaterialGet(data) {
                    return requestApi("/rest/v1/material/get_material/get", data).then(function(result) {
                        return result;
                    });
                }

                function openapiuserAdd(data) {
                    return requestApi("/rest/v1/openapi/user/add", data).then(function(result) {
                        return result;
                    });
                }

                //绑定企业微信
                function qycorpBindpartner() {
                    var data = {
                        method: "dhf.qy.corp.bind.partner",
                    };

                    return requestApi("/rest/v1/php/dhf/qycorp/bindpartner/add", data).then(function(result) {
                        return result;
                    });
                }



                //绑定企业微信
                function qyCorpGet() {
                    var data = {
                        method: "dhf.qy.corp.get",
                    };

                    return requestApi("/rest/v1/php/dhf/qy/corp/get", data).then(function(result) {
                        return result;
                    });
                }


                // function subscribeGet() {
                //     return requestApi("/rest/v1/member/subscribe/get").then(function(result) {
                //         return result;
                //     });
                // }

                //查询是否关注公众号
                function subscribecacheGet(data) {
                    return requestApi("/rest/v1/member/subscribe/cache/get", data).then(function(result) {
                        return result;
                    });
                }

                //聊天记录查询
                function chatRecordGet(data) {
                    return requestApi("/rest/v1/chatrecord/get", data).then(function(result) {
                        if (result.chat_records) {
                            _.map(result.chat_records, function(a) {
                                if (a.msg_body) {
                                    try {
                                        a.msg_body = JSON.parse(a.msg_body);
                                    } catch (e) {
                                        a.msg_body = {};
                                    }
                                } else {
                                    if (a.msg_type == "image") {
                                        a.msg_body = {
                                            media_id: a.media_id,
                                        }
                                    } else {
                                        a.msg_type = "text";
                                        a.msg_body = {
                                            content: a.content,
                                        }
                                    }
                                }
                            })
                        }
                        // //console.error("result", result)
                        return result
                    });
                }


                //活动 添加  
                function giftAdd(xdata) {
                    var data = clone(xdata);
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.gift.add";

                    return requestApi("/rest/v1/php/dhf/gift/add", data).then(function(result) {
                        return result;
                    });
                }
                //活动 查询 
                function dakaAdd(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/daka/add", data).then(function(result) {
                        return result;
                    });
                }
                //活动 查询 
                function giftGet(data) {
                    if (data.content) {
                        data.content.nocache = 1;
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/gift/get", data).then(function(result) {
                        return result;
                    });
                }

                function giftOne(id) {
                    if (id) {
                        var data = {
                            content: {
                                gift_id: id,
                                store_id: $rootScope.store_id
                            }
                        }
                        return giftGet(data).then(function(re) {
                            if (re.gift_list) {
                                return re.gift_list[0];
                            } else {
                                return reject(re);
                            }

                        });
                    } else {
                        return reject();
                    }

                }
                // 
                //活动 查询 
                function giftdetailsGet(data) {
                    if (data.content) {
                        if (data.content.start_time && data.content.end_time) {
                            data.content.start_time = toStdTime(data.content.start_time);
                            data.content.end_time = toStdTime(data.content.end_time);
                        }
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/gift/details/get", data).then(function(result) {
                        return result;
                    });
                }
                //表白活动
                function confessionGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.confession.activity.get";

                    return requestApi("/rest/v1/php/dhf/confession/activity/get", data).then(function(result) {
                        return result;
                    });
                }

                //表白详情
                function confessionDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.confession.detail.get";

                    return requestApi("/rest/v1/php/dhf/confession/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                function confessionAdd(data) {
                    var xdata = confessionData(data);
                    xdata.method = "dhf.confession.activity.update";

                    return requestApi('/rest/v1/php/dhf/confession/activity/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function confessionUpdate(data) {
                    var xdata = confessionData(data);
                    xdata.method = "dhf.confession.activity.update";

                    return requestApi('/rest/v1/php/dhf/confession/activity/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function confessionData(data) {
                    var xdata = clone(data);
                    // console.error(xdata);
                    // return false;
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    if (xdata.position1) {
                        xdata.position1 = JSON.stringify(xdata.position1);
                    }

                    if (xdata.position && xdata.position1) {
                        xdata.position = JSON.parse(xdata.position1);
                    }

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return ddata;
                }

                function confessionItemGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.confession.activity.item.get";

                    return requestApi("/rest/v1/php/dhf/confession/activity/item/get", data).then(function(result) {
                        return result;
                    });
                }

                function confessionItemAdd(confession_activity_id, item) {
                    var data = {
                        "content": {
                            "confession_activity_id": confession_activity_id,
                            "item": JSON.stringify(item)
                        },
                        "method": "dhf.confession.activity.item.add"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/confession/activity/item/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function confessionItemDelete(id, confession_activity_id) {
                    var data = {
                        "content": {
                            "id": id,
                            "confession_activity_id": confession_activity_id
                        },
                        "method": "dhf.confession.activity.item.delete"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/confession/activity/item/delete", ddata).then(function(result) {
                        return result;
                    });
                }
                //优惠券列表
                function couponGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.coupons.get";

                    return requestApi("/rest/v1/php/dhf/coupons/get", data).then(function(result) {
                        return result;
                    });
                }

                function couponAdd(data) {
                    var xdata = couponData(data);
                    xdata.method = "dhf.coupons.add";

                    return requestApi('/rest/v1/php/dhf/coupons/add', xdata).then(function(result) {
                        return result;
                    });
                }

                function couponUpdate(data) {
                    var xdata = couponData(data);
                    // xdata.method = "dhf.coupons.update";
                    xdata.method = "dhf.coupons.add";

                    return requestApi('/rest/v1/php/dhf/coupons/add', xdata).then(function(result) {
                        return result;
                    });
                }

                function couponData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return ddata;
                }

                function couponItemGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.coupons.item.get";

                    return requestApi("/rest/v1/php/dhf/coupons/item/get", data).then(function(result) {
                        return result;
                    });
                }

                function couponItemAdd(coupon_id, item) {
                    var data = {
                        "content": {
                            "coupon_id": coupon_id,
                            "item": JSON.stringify(item)
                        },
                        "method": "dhf.coupons.item.add"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/coupons/item/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function couponItemDelete(id, coupon_id) {
                    var data = {
                        "content": {
                            "id": id,
                            "coupon_id": coupon_id
                        },
                        "method": "dhf.coupons.item.delete"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/coupons/item/delete", ddata).then(function(result) {
                        return result;
                    });
                }

                //审核评价
                function commentsUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/item/comments/update", data).then(function(result) {
                        return result;
                    });
                }

                //评价列表
                function commentsGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/item/comments/get", data).then(function(result) {
                        return result;
                    });
                }

                //点赞列表
                function praiseGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/item/praise/get", data).then(function(result) {
                        return result;
                    });
                }

                //房间预约
                function roomsGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/rooms/get", data).then(function(result) {
                        return result;
                    });
                }

                //添加
                function roomsAdd(data) {
                    var xdata = clone(data);
                    xdata.description = JSON.stringify(html2json(xdata.description));

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return requestApi("/rest/v1/php/dhf/rooms/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //编辑
                function roomsUpdate(data) {
                    var xdata = clone(data);
                    xdata.description = JSON.stringify(html2json(xdata.description));

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return requestApi("/rest/v1/php/dhf/rooms/update", ddata).then(function(result) {
                        return result;
                    });
                }

                //sku删除
                function roomskusDelete(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/rooms/sku/delete", data).then(function(result) {
                        return result;
                    });
                }

                //tag列表
                function roomstagGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/rooms/tag/get", data).then(function(result) {
                        return result;
                    });
                }

                function roomstagAdd(data) {
                    var xdata = clone(data);

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return requestApi("/rest/v1/php/dhf/rooms/tag/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function roomsOrderGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/rooms/order/get", data).then(function(result) {
                        return result;
                    });
                }

                function roomsOrderUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/rooms/order/update", data).then(function(result) {
                        return result;
                    });
                }

                //课程类目
                function nsqCommonAdd(data) {
                    if (data.content) {
                        data.content.type = "item";
                        data.content = angular.toJson(data.content);
                    }

                    return requestApi("/rest/v1/php/dhf/nsq/common/add", data).then(function(result) {
                        return result;
                    });
                }

                //打印指令 
                function printPOs(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/print/pos/add", data).then(function(result) {
                        return result;
                    });
                }

                // /rest/v1/php/dhf/nsq/common/add
                //课程类目
                function classCategoryGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/class/category/get", data).then(function(result) {
                        return result;
                    });
                }

                //课程类目
                function classCategoryUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/class/category/update", data).then(function(result) {
                        return result;
                    });
                }

                //课程类目
                function classCategoryAdd(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/class/category/add", data).then(function(result) {
                        return result;
                    });
                }

                //转发拉人
                function drawpullGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    data.method = "dhf.draw.pull.get";
                    return requestApi("/rest/v1/php/dhf/draw/pull/get", data).then(function(result) {
                        return result;
                    });
                }

                //增加抽奖活动人数
                function drawdetailAdd(draw_id, act_num) {

                    var data = {};
                    data.content = {
                        "detail_add": "manual",
                        "draw_id": draw_id,
                        "act_num": act_num,
                        "store_id": $rootScope.store_id
                    };

                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    data.method = "dhf.draw.detail.add";
                    return requestApi("/rest/v1/php/dhf/draw/detail/add", data).then(function(result) {
                        return result;
                    });
                }

                //抽奖活动参与人数
                function drawdetailGet(page_size, draw_id) {

                    var data = {};
                    data.content = {
                        "page_size": page_size,
                        "draw_id": draw_id,
                        "store_id": $rootScope.store_id
                    };

                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    data.method = "dhf.draw.detail.get";
                    return requestApi("/rest/v1/php/dhf/draw/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                //抽奖活动编辑
                function luckydrawUpdate(data) {
                    var ddata = drawData(data);
                    ddata.method = "dhf.lucky.draw.update";
                    return requestApi("/rest/v1/php/dhf/lucky/draw/update", ddata).then(function(result) {
                        return result;
                    });
                }

                //抽奖活动添加
                function luckydrawAdd(data) {
                    var ddata = drawData(data);
                    ddata.method = "dhf.lucky.draw.add";
                    return requestApi("/rest/v1/php/dhf/lucky/draw/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function drawData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    xdata.introduce = JSON.stringify(html2json(xdata.introduce));
                    if (xdata.introduce1) {
                        xdata.introduce1 = JSON.stringify(html2json(xdata.introduce1));
                    }
                    if (xdata.introduce2) {
                        xdata.introduce2 = JSON.stringify(html2json(xdata.introduce2));
                    }

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);
                    return ddata;
                }

                //抽奖活动列表
                function luckydrawGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }

                    data.method = "dhf.lucky.draw.get";
                    return requestApi("/rest/v1/php/dhf/lucky/draw/get", data).then(function(result) {
                        return result;
                    });
                }

                //订单转单
                function orderPickpointUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.order.pickpoint.update";
                    return requestApi("/rest/v1/php/dhf/order/pickpoint/update", data).then(function(result) {
                        return result;
                    });
                }

                //删除发货点
                function pickpointDelete(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.store.pickpoint.delete";
                    return requestApi("/rest/v1/php/dhf/store/pickpoint/delete", data).then(function(result) {
                        return result;
                    });
                }

                function pickpointStatusUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.store.pickpoint.update";
                    return requestApi("/rest/v1/php/dhf/store/pickpoint/update", data).then(function(result) {
                        return result;
                    });
                }

                //发货点列表
                function pickpointGet(data, nocache) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.store.pickpoint.get";
                    // , 3600 * 24 * 30
                    return requestApi("/rest/v1/php/dhf/store/pickpoint/get", data, nocache ? 0 : 3600 * 24 * 30).then(function(result) {
                        return result;
                    });
                }
                //发货点添加
                function pickpointUpdate(xdata) {

                    console.error("data", xdata.content.p_pickpoint_id);
                    if ($rootScope.is_main == 2 && xdata.content.p_pickpoint_id) {
                        helper.myAlert("发货点只能主店修改！");
                        return reject();
                    }

                    var data = clone(xdata);
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.store.pickpoint.update";
                    return requestApi("/rest/v1/php/dhf/store/pickpoint/update", data).then(function(result) {
                        return result;
                    });
                }
                //获取 线上版本 号列表
                function WxGettemplatedraftlist(authorizer_appid) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/wxa/gettemplatedraftlist?access_token=TOKEN", "POST").then(function(result) {
                        return result;
                    });
                }

                //删除 公众号 素材
                function wxDelMaterial(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.errmsg == "ok") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }
                //群发 
                function wxSendall(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.errmsg == "send job submission success") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }
                //预览
                function preview(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.errmsg == "preview success") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }

                //修改
                function wxUpdateNews(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.errmsg == "ok") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }
                //新增永久素材
                function wxAddNews(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.media_id) {
                            return result.media_id;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }


                //设置wifi完成页面
                function gzhWifiBarSet(authorizer_appid, shop_id, bar_type) {
                    var data = {
                        "shop_id": shop_id,
                        "bar_type": bar_type || 0
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/bar/set?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }
                //设置wifi完成页面
                function gzhWifiHomePageSet(authorizer_appid, shop_id, wxa_user_name) {
                    var data = {
                        "shop_id": shop_id,
                        "template_id": 2,
                        "struct": {
                            "wxa_user_name": wxa_user_name,
                            "wxa_path": "pages/index/index"
                        }
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/homepage/set?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }
                //设置wifi完成页面
                function gzhWifiFinishPageSet(authorizer_appid, shop_id, wxa_user_name) {
                    var data = {
                        "shop_id": shop_id,
                        "wxa_user_name": wxa_user_name,
                        "wxa_path": "pages/index/index",
                        "finishpage_type": 1,
                        "finishpage_url": "",
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/finishpage/set?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }

                //获取公众号关联的小程序
                function gzhWxopenWxamplink(authorizer_appid) {
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplinkget?access_token=TOKEN", "POST", {}).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return result.wxopens.items;
                        } else if (result.errmsg.indexOf("unauthorized")) {
                            helper.myAlert("公众号没有授权所有权限，请重新授权公众号，修改勾选所有权限", "#/store/config?store_id=" + $rootScope.store_id, 999);
                            return reject(result);
                        }
                    });
                }

                //公众号接触关联小程序
                function gzhUnLinkApp(authorizer_appid, appid) {
                    var data = {
                        "appid": appid,
                    }

                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/wxopen/wxampunlink?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errcode == 0) {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg + '<br><br>反复出现上面错误，<a href="https://mp.weixin.qq.com/" target="_blank">请点击这里进入公众号</a>，左侧菜单【小程序管理】解除关联小程序。', null, 999);
                            return reject(result);
                        }
                    });
                }

                //公众号关联小程序
                function gzhLinkApp(authorizer_appid, appid) {
                    var data = {
                        "appid": appid,
                        "notify_users": "1",
                        "show_profile": "1",
                    }

                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/wxopen/wxamplink?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errcode == 0) {
                            return true;
                        } else {
                            helper.myAlert("错误：" + result.errmsg + '<br><br>反复出现上面错误，<a href="https://mp.weixin.qq.com/" target="_blank">请点击这里进入公众号</a>，左侧菜单【小程序管理】关联小程序。', null, 999);
                            return reject(result);
                        }
                    });
                }

                //设备二维码
                function gzhWifiQrcodeGet(authorizer_appid, shop_id, ssid) {
                    var data = {
                        "shop_id": shop_id,
                        "ssid": ssid,
                        "img_id": 1,
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/qrcode/get?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errcode == 0) {
                            return ERP_CONFIG.apiUrl + "/public/imgproxy/get?url=" + encodeURIComponent(result.data.qrcode_url);
                        } else {
                            helper.myAlert(result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }

                //添加设备
                function gzhWifiDeviceAdd(authorizer_appid, shop_id, ssid, password) {
                    var data = {
                        "shop_id": shop_id,
                        "ssid": ssid,
                        "password": password,
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/device/add?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return true;
                        } else {
                            if (result.errmsg.indexOf("device exist") != -1) {
                                var msg = "设备已存在，要重复添加，请点击【清空门店wifi】再添加";
                            } else {
                                var msg = result.errmsg;
                            }
                            helper.myAlert(msg, null, 9999);
                            return reject(result);
                        }
                    });
                }

                //删除设备
                function gzhWifiDeviceDelete(authorizer_appid, bssid) {
                    var data = {
                        "bssid": bssid
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/device/delete?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errcode == 0) {
                            return result.data;
                        } else {
                            helper.myAlert(result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }

                //清空门店设备
                function gzhWifiShopClean(authorizer_appid, shop_id) {
                    var data = {
                        "shop_id": shop_id
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/shop/clean?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errcode == 0) {
                            return true;
                        } else {
                            helper.myAlert(result.errmsg, null, 999);
                            return reject(result);
                        }
                    });
                }

                //公众号门店列表
                function gzhWifiShop(authorizer_appid, shop_id) {
                    var data = {
                        "shop_id": shop_id
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/shop/get?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return result.data;
                        } else {
                            return result;
                        }
                    });
                }

                //公众号门店列表
                function gzhWifiDevice(authorizer_appid, shop_id) {
                    var data = {
                        "pageindex": 1,
                        "pagesize": 10
                    }
                    if (shop_id) {
                        data.shop_id = shop_id;
                    }

                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/device/list?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return result.data;
                        } else {
                            return result;
                        }
                    });
                }

                //公众号门店列表
                function gzhWifiShopList(authorizer_appid) {
                    var data = {
                        "pageindex": 1,
                        "pagesize": 20
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/shop/list?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            return result.data;
                        } else {
                            return result;
                        }
                    });
                }
                //wifi
                function wifiToken(authorizer_appid) {
                    var data = {
                        "callback_url": window.location.href
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/openplugin/token?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result && result.errmsg == "ok") {
                            result.data.callback_url = data.callback_url;
                            result.data.auth_url = "https://wifi.weixin.qq.com/biz/mp/thirdProviderPlugin.xhtml?token=" + result.data.wifi_token;
                            return result.data;
                        } else {
                            return reject(result);
                        }
                    });
                }

                //wifi设备
                function wifiDeviceList(authorizer_appid) {
                    var data = {
                        "pageindex": 1,
                        "pagesize": 10
                    }
                    return wxproxy(authorizer_appid, "https://api.weixin.qq.com/bizwifi/device/list?access_token=TOKEN", "POST", data).then(function(result) {
                        return result.data;
                    });
                }

                //nsq请求
                function nsqRequest(data) {
                    // console.error("data-->", data);
                    if (data.content) {
                        data.content.type = "dazhe";
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.nsq.common.request";
                        return requestApi("/rest/v1/php/dhf/nsq/common/add", data).then(function(result) {
                            return result;
                        });
                    }
                }

                //h5活动的
                function h5hdAdd(data) {
                    var ddata = h5date(data);
                    return requestApi("/rest/v1/php/dhf/h5hd/add", ddata).then(function(result) {
                        return result;
                    });
                }
                //h5活动的
                function h5hdUpdate(data) {
                    var ddata = h5date(data);
                    return requestApi("/rest/v1/php/dhf/h5hd/update", ddata).then(function(result) {
                        return result;
                    });
                }


                //活动的课程表
                function classUpdate(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //活动的课程表
                function classdetailGet(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/details/get/", xdata).then(function(result) {
                        return result;
                    });
                }

                //活动的课程表
                function classdetailAdd(data) {
                    var xdata = clone(data);
                    if (xdata.content.class_tiem) {
                        xdata.content.class_tiem = toStdTime(xdata.content.class_tiem);
                    }
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/details/add/", xdata).then(function(result) {
                        return result;
                    });
                }

                //活动的课程表
                function classdetailUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.content.class_tiem) {
                        xdata.content.class_tiem = toStdTime(xdata.content.class_tiem);
                    }
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/details/update/", xdata).then(function(result) {
                        return result;
                    });
                }

                //活动的课程表
                function classAdd(data) {
                    var xdata = clone(data);
                    if (xdata.content.expiry_time) {
                        xdata.content.expiry_time = toStdTime(xdata.content.expiry_time);
                    }
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //活动的课程表
                function classGet(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);
                    return requestApi("/rest/v1/php/dhf/class/get", xdata).then(function(result) {
                        return result;
                    });
                }

                function h5date(data) {
                    var xdata = clone(data);
                    if (xdata.content.start_time && xdata.content.end_time) {
                        xdata.content.start_time = toStdTime(xdata.content.start_time);
                        xdata.content.end_time = toStdTime(xdata.content.end_time);
                    }
                    xdata.content = angular.toJson(xdata.content);
                    return xdata;
                }
                //h5活动的
                function h5hddetailGet(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/h5hd/details/get", data).then(function(result) {
                        return result;
                    });
                }
                //h5活动的
                function h5hddetailUpdate(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/h5hd/details/update", data).then(function(result) {
                        return result;
                    });
                }

                //h5活动的
                function h5hdGet(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/h5hd/get", data).then(function(result) {
                        return result;
                    });
                }

                //h5活动的
                function h5hdDel(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/h5hd/del", data).then(function(result) {
                        return result;
                    });
                }

                //留言 backliuyanAdd
                function backliuyanAdd(data) {
                    data.content = angular.toJson(data.content);
                    var api = "";
                    if (sessionService.get('token')) {
                        api = "/rest/v1/php/dhf/back/liuyan/add";
                    } else {
                        api = "/public/php/dhf/back/liuyan/add";
                    }
                    return requestApi(api, data).then(function(result) {
                        return result;
                    });
                }

                function backliuyanGet(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/back/liuyan/get", data).then(function(result) {
                        return result;
                    });
                }

                //留言 
                function buyerliuyanAdd(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/buyer/liuyan/add", data).then(function(result) {
                        return result;
                    });
                }

                function buyerliuyanGet(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/buyer/liuyan/get", data).then(function(result) {
                        return result;
                    });
                }

                function mianfuAdd(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/mianfu/add", data).then(function(result) {
                        return result;
                    });
                }

                function mianfuGet(data) {
                    data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/php/dhf/mianfu/get", data).then(function(result) {
                        return result;
                    });
                }




                //订单附加信息获取
                function orderExtInfoGet(tid) {
                    var data = {};
                    data.content = {
                        "store_id": $rootScope.store_id,
                        "tid": tid
                    };
                    data.content = angular.toJson(data.content);

                    data.method = "dhf.order.extinfo.get";
                    return requestApi("/rest/v1/php/dhf/order/extinfo/get", data).then(function(result) {
                        return result;
                    });
                }

                //永久素材删除
                function simutaskDel(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/material/simutask/delete", xdata).then(function(result) {
                        return result;
                    });
                }

                //永久素材查询
                function simutaskGet(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/material/simutask/get", xdata).then(function(result) {
                        return result;
                    });
                }

                function simutaskGetOne(data) {
                    console.error("datadata", data, data.length);
                    return simutaskGet(data).then(function(result) {
                        if (result.mate_simu_tasks) {
                            return result.mate_simu_tasks[0];
                        } else {
                            return resolve();
                        }
                    });
                }

                //永久素材添加
                function simutaskAdd(data) {
                    var xdata = clone(data);
                    // data.content = angular.toJson(data.content);
                    return requestApi("/rest/v1/material/simutask/add", xdata).then(function(result) {
                        return result;
                    });
                }


                //备份装修模板添加
                function userlayoutAdd(xdata) {
                    var data = clone(xdata);
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.user.layout.add";
                    return requestApi("/rest/v1/php/dhf/user/layout/add", data).then(function(result) {
                        return result;
                    });
                }

                //备份装修模板删除
                function userlayoutDel(user_layout_id) {
                    var data = {};
                    data.content = angular.toJson({
                        user_layout_id: user_layout_id
                    });
                    data.method = "dhf.user.layout.delete";
                    return requestApi("/rest/v1/php/dhf/user/layout/delete", data).then(function(result) {
                        return result;
                    });
                }

                //备份装修模板查询
                function userlayoutGet(xdata) {
                    var data = clone(xdata);
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.user.layout.get";
                    return requestApi("/rest/v1/php/dhf/user/layout/get", data).then(function(result) {
                        return result;
                    });
                }


                //装修模板添加
                function adminlayoutAdd(xdata) {
                    var data = clone(xdata);
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.admin.layout.add";
                    return requestApi("/rest/v1/php/dhf/layout/add", data).then(function(result) {
                        return result;
                    });
                }

                //装修模板修改
                function adminlayoutUpdate(xdata) {
                    var data = clone(xdata);
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.admin.layout.update";
                    return requestApi("/rest/v1/php/dhf/layout/update", data).then(function(result) {
                        return result;
                    });
                }

                //装修模板查询
                function adminlayoutGet(xdata) {
                    var data = clone(xdata);
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.admin.layout.get";
                    return requestApi("/rest/v1/php/dhf/layout/get", data).then(function(result) {
                        return result;
                    });
                }

                function adminlayoutOne(data) {
                    if (data.content.admin_layout_id) {
                        return adminlayoutGet(data).then(function(result) {
                            return result.adminlayouts[0];
                        });
                    } else {
                        return reject();
                    }
                }

                //装修模板删除
                function adminlayoutDel(admin_layout_id) {
                    var data = {
                        content: {
                            admin_layout_id: admin_layout_id
                        }
                    }
                    data.content = angular.toJson(data.content);
                    data.method = "dhf.admin.layout.delete";
                    return requestApi("/rest/v1/php/dhf/layout/delete", data).then(function(result) {
                        return result;
                    });
                }

                function sceneSave(key, value) {
                    var data = {};
                    data.content = {
                        "skey": key,
                        "svalue": value
                    };
                    data.content = angular.toJson(data.content);

                    data.method = "dhf.admin.layout.add";
                    return requestApi("/rest/v1/php/dhf/scene/save", data).then(function(result) {
                        return result.Msg == "ok";
                    });
                }

                function sceneGet(key) {
                    var data = {};
                    data.content = {
                        "skey": key
                    };
                    data.content = angular.toJson(data.content);

                    data.method = "dhf.scene.get";
                    return requestApi("/rest/v1/php/dhf/scene/get", data).then(function(result) {
                        return result.result || [];
                    });
                }

                //红包
                function hongbaoGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.hongbao.get";
                        return requestApi("/rest/v1/php/dhf/hongbao/get", data).then(function(result) {
                            return result;
                        });
                    }
                }

                function hongbaoGetOne(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.hongbao.get";

                        return requestApi("/rest/v1/php/dhf/hongbao/get", data).then(function(result) {
                            if (result.total_count) {
                                return result.hongbao_list[0];
                            }
                        });
                    }
                }

                function hongbaoAdd(data) {
                    var ddata = hongbaoData(data);
                    ddata.method = "dhf.hongbao.add";
                    return requestApi("/rest/v1/php/dhf/hongbao/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function hongbaoUpdate(data) {
                    var ddata = hongbaoData(data);
                    ddata.method = "dhf.hongbao.update";
                    return requestApi("/rest/v1/php/dhf/hongbao/update", ddata).then(function(result) {
                        return result;
                    });
                }

                function hongbaoData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }
                    var ddata = [];
                    ddata.content = angular.toJson(xdata);
                    return ddata;
                }

                function hongbaoDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.hongbao.detail.get";
                    return requestApi("/rest/v1/php/dhf/hongbao/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                function withdrawalLogGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.withdrawal.log.get";
                    return requestApi("/rest/v1/php/dhf/withdrawal/log/get", data).then(function(result) {
                        return result;
                    });
                }

                //服务活动
                function serviceactivityGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.service.activity.get";
                    return requestApi("/rest/v1/php/dhf/service/activity/get", data).then(function(result) {
                        return result;
                    });
                }

                //服务活动添加
                function serviceactivityAdd(data) {
                    var ddata = activityData(data);
                    ddata.method = "dhf.service.activity.add";
                    return requestApi("/rest/v1/php/dhf/service/activity/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //服务活动添加
                function serviceactivityUpdate(data) {
                    var ddata = activityData(data);
                    ddata.method = "dhf.service.activity.update";
                    return requestApi("/rest/v1/php/dhf/service/activity/update", ddata).then(function(result) {
                        return result;
                    });
                }

                function activityData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    xdata.introduce = JSON.stringify(html2json(xdata.introduce))

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);
                    return ddata;
                }

                //服务
                function fuwuGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.get";
                    return requestApi("/rest/v1/php/dhf/fuwu/get", data).then(function(result) {
                        return result;
                    });
                }

                //服务版本添加
                function fuwuAdd(data) {
                    var xdata = clone(data);
                    xdata.introduce = JSON.stringify(html2json(xdata.introduce))

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    ddata.method = "dhf.fuwu.add";
                    return requestApi("/rest/v1/php/dhf/fuwu/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //服务版本编辑
                function fuwuUpdate(data) {
                    var xdata = clone(data);
                    xdata.introduce = JSON.stringify(html2json(xdata.introduce));

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    ddata.method = "dhf.fuwu.add";
                    return requestApi("/rest/v1/php/dhf/fuwu/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //服务订单列表
                function fuwuOrderGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.order.get";
                    return requestApi("/rest/v1/php/dhf/fuwu/order/get", data).then(function(result) {
                        return result;
                    });
                }

                //服务订单添加
                function fuwuOrderAdd(fuwu_id, cycle) {
                    var data = {};
                    data.content = {
                        "fuwu_id": fuwu_id,
                        "cycle": cycle
                    };
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    data.method = "dhf.fuwu.order.add";
                    return requestApi("/rest/v1/php/dhf/fuwu/order/add", xdata).then(function(result) {
                        return result;
                    });
                }

                function fuwuManualOrderAdd(data) {
                    var xdata = clone(data);

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    data.method = "dhf.fuwu.order.add";
                    return requestApi("/rest/v1/php/dhf/fuwu/order/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //取消订单
                function cancleOrder(order_id) {
                    var data = {};
                    data.content = {
                        "fuwu_order_id": order_id
                    };
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    data.method = "dhf.fuwu.order.update";
                    return requestApi("/rest/v1/php/dhf/fuwu/order/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //服务代理订单
                function fuwuDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.detail.get";

                    return requestApi("/rest/v1/php/fuwu/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                //结算记录
                function fuwuClearingGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.clearing.get";

                    return requestApi("/rest/v1/php/fuwu/clearing/get", data).then(function(result) {
                        return result;
                    });
                }

                //更改结算状态
                function fuwuClearingGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.clearing.get";

                    return requestApi("/rest/v1/php/fuwu/clearing/get", data).then(function(result) {
                        return result;
                    });
                }

                function fuwuDetailUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.detail.update";

                    return requestApi("/rest/v1/php/fuwu/detail/update", data).then(function(result) {
                        return result;
                    });
                }

                //更改结算状态
                function fuwuClearingUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.clearing.status.update";

                    return requestApi("/rest/v1/php/fuwu/clearing/status/update", data).then(function(result) {
                        return result;
                    });
                }

                function fuwuClearingDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.clearing.detail.get";

                    return requestApi("/rest/v1/php/fuwu/clearing/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                function zhuanqianOrderGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fuwu.distribution.order.get";

                    return requestApi("/rest/v1/php/fuwu/distribution/order/get", data).then(function(result) {
                        return result;
                    });
                }

                //报名活动
                function huodongGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.huodong.get";
                    return requestApi("/rest/v1/php/dhf/huodong/get", data).then(function(result) {
                        return result;
                    });
                }

                //报名活动添加
                function huodongAdd(data) {
                    var ddata = huodongData(data);
                    ddata.method = "dhf.huodong.add";
                    return requestApi("/rest/v1/php/dhf/huodong/add", ddata).then(function(result) {
                        return result;
                    });
                }

                //报名活动添加
                function huodongUpdate(data) {
                    var ddata = huodongData(data);
                    ddata.method = "dhf.huodong.update";
                    return requestApi("/rest/v1/php/dhf/huodong/update", ddata).then(function(result) {
                        return result;
                    });
                }

                function huodongData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    if (xdata.huodong_start_time && xdata.huodong_end_time) {
                        xdata.huodong_start_time = toStdTime(xdata.huodong_start_time);
                        xdata.huodong_end_time = toStdTime(xdata.huodong_end_time);
                    }

                    xdata.introduce = JSON.stringify(html2json(xdata.introduce))
                    xdata.payed_out = JSON.stringify(html2json(xdata.payed_out));

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);
                    return ddata;
                }

                //报名活动详情表
                function huodongDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.huodong.detail.get";
                    return requestApi("/rest/v1/php/dhf/huodong/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                function huodongDetailUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.huodong.detail.update";
                    return requestApi("/rest/v1/php/dhf/huodong/detail/update", data).then(function(result) {
                        return result;
                    });
                }

                //存储秘钥
                function saveSecretKey(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.huodong.secretkey.add";
                    return requestApi("/rest/v1/php/dhf/huodong/secretkey/add", data).then(function(result) {
                        return result;
                    });
                }

                //订单折扣修改
                function discountUpdate(data) {
                    var xdata = clone(data);
                    xdata.adjust_discounts = angular.toJson(xdata.adjust_discounts);

                    return requestApi("/rest/v1/order/discount/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //自动回复规则查询
                function autorspcfgGet(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/autorspcfg/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //自动回复更新
                function autorspcfgUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.session_reply_info) {
                        xdata.session_reply_info = JSON.stringify(xdata.session_reply_info);
                    }

                    if (xdata.rcvmsg_reply_info) {
                        xdata.rcvmsg_reply_info = JSON.stringify(xdata.rcvmsg_reply_info);
                    }

                    if (xdata.subscribe_reply_info) {
                        xdata.subscribe_reply_info = JSON.stringify(xdata.subscribe_reply_info);
                    }

                    return requestApi("/rest/v1/autorspcfg/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //小程序配置
                function xcxAppJson() {
                    return $http({
                        method: "GET",
                        url: "/web/dhfshop/app/scripts/config/app.json",
                    }).then(function(res) {
                        return res.data;
                    });
                }

                //获取最后1次审核状态
                function getLatestAuditStatus(authorizer_appid) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=TOKEN", "GET").then(function(result) {
                        return result;
                    });
                }

                //微信代理 content是object类型，只有POST请求时入参
                function wxproxy(authorizer_appid, url, req_method, content) {
                    content = content || "";
                    content = angular.toJson(content);
                    req_method = req_method || "GET";
                    return requestApi("/rest/v1/wxproxy/get", {
                        authorizer_appid: authorizer_appid,
                        url_prefix: url,
                        req_method: req_method,
                        content: content
                    }).then(function(result) {
                        return result;
                    });
                }

                //资源列表
                function resourceGet(data) {
                    return requestApi("/rest/v1/resource/get", data, 0).then(function(result) {
                        _.map(result.resources, function(one) {
                            one.action = _.compact(one.action.split(","));
                            return one;
                        });

                        return result;
                    });
                }

                //根据id查询1个资源
                function resourcesOne(id, identity) {
                    if (id) {
                        var data = {
                            query: {
                                "id": id
                            }
                        };
                    }
                    if (identity) {
                        var data = {
                            query: {
                                "identity": identity
                            }
                        };

                    }

                    return resourceGet(data).then(function(result) {
                        if (result.resources && result.resources.length == 1) {
                            return result.resources[0];
                        } else {
                            return reject("没有找到identity:" + identity + "的资源");
                        }
                    });
                }

                //角色列表
                function roleGet(xdata) {
                    var data = clone(xdata);
                    data.order_by = "created_at:desc";
                    return requestApi("/rest/v1/role/get", data).then(function(result) {
                        if (result && result.total_count) {
                            _.map(result.roles, function(a) {
                                if (a.menu) {
                                    a.menu = JSON.parse(a.menu);
                                }
                                if (a.data_range) {
                                    a.data_range = JSON.parse(a.data_range);
                                }

                                if (!a.menu) {
                                    a.menu = [];
                                }
                                _.map(a.permissions, function(b) {
                                    b.action = b.action ? b.action.split(",") : [];
                                });
                            });
                        }
                        return result;
                    });
                }

                //角色列表
                function roleOne(id) {
                    return roleGet({
                        query: {
                            "role_id": id
                        }
                    }).then(function(result) {
                        if (result && result.total_count == 1) {
                            return result.roles[0];
                        } else {
                            reject("没有发现id：" + id + "的角色");
                        }
                    });
                }

                //角色删除
                function roleDel(role_id) {
                    if (role_id == 1) {
                        return reject("不能删除管理员账户！");
                    }
                    return requestApi("/rest/v1/role/delete", {
                        role_id: role_id
                    }).then(function(result) {
                        return result;
                    });
                }

                //角色添加
                function roleAdd(xdata) {
                    // console.error("-----", xdata);return;
                    var data = clone(xdata);
                    var method = data.role_id ? "update" : "add";
                    //处理
                    data.permissions = _.map(data.permissions, function(one) {
                        // console.log("11111", one)
                        var d = {
                            name: one.name,
                            identity: one.identity,
                            action: one.action.join(","),
                        }
                        if (one.id) {
                            d.id = one.id;
                        }
                        return d;
                    });

                    data.permissions = angular.toJson({
                        "permissions": data.permissions
                    });
                    data.menu = angular.toJson(data.menu);
                    data.data_range = angular.toJson(data.data_range);
                    return requestApi("/rest/v1/role/" + method, data).then(function(result) {
                        return result;
                    });
                }


                //打折查询
                function dazheGet(query) {
                    return requestApi("/rest/v1/activity/get", query).then(function(result) {
                        return result;
                    });
                }

                //打折add
                function dazheAdd(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi("/rest/v1/activity/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //添加打折商品
                function addItemCuxiao(data) {
                    var xdata = clone(data);
                    if (xdata.activity_items) {
                        xdata.activity_items = angular.toJson({
                            "activity_items": xdata.activity_items
                        });
                    }
                    return requestApi("/rest/v1/activity/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //移除打折商品
                function removeItemCuxiao(data) {
                    var xdata = clone(data);
                    if (!xdata.id) {
                        helper.myAlert("商品移除错误");
                        return false;
                    }
                    return requestApi("/rest/v1/activity/delete", xdata).then(function(result) {
                        return result;
                    });
                }

                //参加活动的商品列表
                function actItemGet(data) {
                    return requestApi("/rest/v1/activity/get", data).then(function(result) {
                        return result;
                    });
                }

                //打折add
                function dazheUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi('/rest/v1/activity/update', xdata).then(function(result) {
                        return result;
                    });
                }

                //打折delete
                function dazheDelete(data) {
                    return requestApi('/rest/v1/activity/delete', data).then(function(result) {
                        return result;
                    });
                }

                //邮费模板列表
                function postfeeGet(query, cb) {
                    // var deferred = $q.defer();

                    // getAllCity(function() {
                    return requestApi("/rest/v1/faretemp/get", query).then(function(result) {
                        if (result.total_count) {
                            for (var i in result.fare_temp) {
                                for (var reg in result.fare_temp[i].carry_modes) {
                                    // || result.fare_temp[i].carry_modes[reg].region != false
                                    if (result.fare_temp[i].carry_modes[reg].region != "1") {
                                        var region = result.fare_temp[i].carry_modes[reg].region;
                                        var area_ids = region.split(",");
                                        // var ex = {};

                                        // for (var q in area_ids) {
                                        //     var a = {};
                                        //     a[area_ids[q]] = $rootScope.citys[area_ids[q]]
                                        //     ex[area_ids[q]] = a;
                                        // }
                                        result.fare_temp[i].carry_modes[reg].region = area_ids;
                                        result.fare_temp[i].carry_modes[reg].selectedCitys = area_ids;
                                    }
                                }
                            }
                            if (cb) cb(result);
                            // deferred.resolve(result);
                            return result;
                        }
                    });
                    // });
                    // return deferred.promise;
                }

                function getAllCity(cb) {
                    // if ($rootScope.citys) {
                    //     cb($rootScope.citys);
                    //     return $rootScope.citys
                    // }
                    $rootScope.citys = {};

                    async.map([1, 2, 3, 4, 5], function(page_no, call) {
                        var qeurys = {
                            page_no: page_no,
                            page_size: 1000
                        };
                        areaGet(qeurys).then(function(r) {
                            if (r.total_count) {
                                for (var a in r.areas) {
                                    $rootScope.citys[r.areas[a].area_id] = r.areas[a].area;
                                }
                            }
                            call(null, null);
                        });
                    }, function(e, r) {
                        // console.error($rootScope.citys);
                        cb($rootScope.citys);
                    })
                }

                //包邮add
                function postfeeAdd(data) {
                    var xdata = clone(data);
                    xdata.carry_modes = angular.toJson({
                        "carry_modes": xdata.carry_modes
                    });

                    return requestApi("/rest/v1/faretemp/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //邮费模板编辑
                function postfeeUpdate(data) {
                    console.error("data", data);
                    if ($rootScope.is_main == 2 && data.remark) {
                        helper.myAlert("邮费模板只能主店修改！");
                        return reject();
                    }
                    var xdata = clone(data);
                    if (xdata.carry_modes) {
                        xdata.carry_modes = angular.toJson({
                            "carry_modes": xdata.carry_modes
                        });
                    }

                    return requestApi("/rest/v1/faretemp/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //邮费模板删除
                function postfeeDelete(data) {
                    return requestApi("/rest/v1/faretemp/delete", data).then(function(result) {
                        return result;
                    });
                }

                function getProvinceCity(cb) {
                    var pro = [];
                    areaGet({
                        query: {
                            parent_id: 0
                        },
                        page_size: 34
                    }).then(function(provinces) {
                        async.mapSeries(provinces.areas, function(province, call) {

                            var a = {
                                id: province.area_id,
                                pId: province.parent_id,
                                name: province.area,
                                nocheck: false,
                                checked: false,
                                open: true
                            };
                            var q = [];
                            areaGet({
                                query: {
                                    parent_id: province.area_id
                                },
                                page_size: 100,
                                "order_by": "area_id:asc"
                            }).then(function(citys) {
                                async.map(citys.areas, function(city, call) {
                                    var b = {
                                        id: city.area_id,
                                        pId: city.area_id,
                                        name: city.area,
                                        nocheck: false,
                                        checked: false,
                                        open: false,
                                        chkDisabled: false
                                    };
                                    q.push(b);
                                    call(null, null)
                                }, function(e, r) {
                                    if (_.size(q)) {
                                        a.children = q;
                                    } else {
                                        a = {
                                            id: province.area_id,
                                            pId: province.parent_id,
                                            name: province.area,
                                            nocheck: false,
                                            checked: false,
                                            open: true
                                        };
                                    }
                                    pro.push(a);
                                })
                            });
                            call(null, null);
                        }, function(e, r) {
                            cb(pro);
                        });
                    });
                }

                //阶梯运费查询
                function stepfreightGet(query) {
                    return requestApi("/rest/v1/stepfreight/get", query).then(function(result) {
                        return result;
                    });
                }

                //阶梯运费设置
                function stepfreightAdd(data) {
                    var xdata = clone(data);
                    if (xdata.distance_fees)
                        xdata.distance_fees = angular.toJson({
                            "distance_fees": xdata.distance_fees
                        });

                    if (xdata.weight_fees)
                        xdata.weight_fees = angular.toJson({
                            "weight_fees": xdata.weight_fees
                        });

                    if (xdata.period_fees)
                        xdata.period_fees = angular.toJson({
                            "period_fees": xdata.period_fees
                        });

                    return requestApi("/rest/v1/stepfreight/add", xdata).then(function(result) {
                        return result;
                    });
                }

                function stepfreightUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.distance_fees)
                        xdata.distance_fees = angular.toJson({
                            "distance_fees": xdata.distance_fees
                        });

                    if (xdata.weight_fees)
                        xdata.weight_fees = angular.toJson({
                            "weight_fees": xdata.weight_fees
                        });

                    if (xdata.period_fees)
                        xdata.period_fees = angular.toJson({
                            "period_fees": xdata.period_fees
                        });

                    return requestApi("/rest/v1/stepfreight/update", xdata).then(function(result) {
                        return result;
                    });
                }

                function stepfreightDelete(query) {
                    return requestApi("/rest/v1/stepfreight/delete", query).then(function(result) {
                        return result;
                    });
                }

                /*
                 * 砍价
                 */

                //砍价查询
                function kanjiaGet(data) {
                    if (data) {
                        data.query = {
                            store_id: $rootScope.store_id
                        }
                    }
                    return requestApi("/rest/v1/bargainrule/get", data).then(function(result) {
                        return result;
                    });
                }

                //单个砍价活动
                function kanjiaGetOne(data) {
                    return requestApi("/rest/v1/bargainrule/get", data).then(function(result) {
                        // return result;
                        if (result.total_count) {
                            return result.bargain_rules[0];
                        }
                    });
                }

                // 砍价添加
                function kanjiaAdd(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi("/rest/v1/bargainrule/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //砍价更新
                function kanjiaUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi('/rest/v1/bargainrule/update', xdata).then(function(result) {
                        return result;
                    });
                }

                //砍价删除
                function kanjiaDelete(data) {
                    return requestApi('/rest/v1/bargainrule/delete', data).then(function(result) {
                        return result;
                    });
                }



                //q获取买家用户微信信息
                function buyerbasicinfoGet(data) {
                    return requestApi("/rest/v1/buyer/basicinfo/get", data).then(function(result) {
                        return result;
                    });
                }

                // 
                //添加桌子类型
                function tabletypeAdd(data) {
                    var xdata = phparytwojson(data);
                    return requestApi("/rest/v1/php/dhf/tabletype/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //查询桌子类型
                function tabletypeGet(data, type) {
                    var xdata = phparytwojson(data);
                    var cache = type ? 0 : 3600 * 24 * 30;
                    return requestApi("/rest/v1/php/dhf/tabletype/get", xdata, cache).then(function(result) {
                        return result;
                    });
                }

                function phparytwojson(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);
                    return xdata;
                }
                //查询桌子类型
                function tabletypeDelete(data) {
                    var xdata = phparytwojson(data);
                    return requestApi("/rest/v1/php/dhf/tabletype/delete", xdata).then(function(result) {
                        return result;
                    });
                }



                //添加桌子
                function tableAdd(data) {
                    var xdata = phparytwojson(data);
                    return requestApi("/rest/v1/php/dhf/table/add", xdata).then(function(result) {
                        return result;
                    });
                }



                //删除桌子
                function tableDelete(data) {
                    var xdata = phparytwojson(data);
                    return requestApi("/rest/v1/php/dhf/table/delete", xdata).then(function(result) {
                        return result;
                    });
                }

                //查询桌子
                function tableGet(data) {
                    var xdata = phparytwojson(data);
                    return requestApi("/rest/v1/php/dhf/table/get", xdata).then(function(result) {
                        return result;
                    });
                }
                // 

                //查询公共周期
                function periodstlGet(data) {
                    return requestApi("/rest/v1/group/periodstl/get", data).then(function(result) {
                        return result;
                    });
                }

                //公共周期生成私有模板
                function periodstlAdd(data) {
                    return requestApi("/rest/v1/group/periodstl/add", data).then(function(result) {
                        return result;
                    });
                }

                //公共时段生成私有时段模板
                function groupTimeslotstlAdd(data) {
                    return requestApi("/rest/v1/group/timeslotstl/add", data).then(function(result) {
                        return result;
                    });
                }

                // 
                //查询公共周期
                function periodGet(data) {
                    return requestApi("/rest/v1/period/get", data).then(function(result) {
                        return result;
                    });
                }

                //周期
                function periodUpdate(data) {
                    return requestApi("/rest/v1/period/update", data).then(function(result) {
                        return result;
                    });
                }

                //周期
                function periodStatusUpdate(data) {
                    return requestApi("/rest/v1/period/status/update", data).then(function(result) {
                        return result;
                    });
                }


                //查询公共周期
                function timeslotGet(data) {
                    return requestApi("/rest/v1/timeslot/get", data).then(function(result) {
                        return result;
                    });
                }

                //查询公共周期
                function reservationGet(data) {
                    return requestApi("/rest/v1/reservation/get", data).then(function(result) {
                        return result;
                    });
                }

                //公共周期
                function timeslotUpdate(data) {
                    return requestApi("/rest/v1/timeslot/update", data).then(function(result) {
                        return result;
                    });
                }

                //公共周期
                function periodstlUpdate(data) {
                    return requestApi("/rest/v1/periodstl/update", data).then(function(result) {
                        return result;
                    });
                }
                // 
                function timeslotstlGet(data) {
                    return requestApi("/rest/v1/group/timeslotstl/get", data).then(function(result) {
                        return result;
                    });
                }

                //查询公共周期
                function timeslotstlAdd(data) {
                    return requestApi("/rest/v1/timeslotstl/add", data).then(function(result) {
                        return result;
                    });
                }
                // 
                //查询公共周期
                function timeslotstlDelete(data) {
                    return requestApi("/rest/v1/timeslotstl/delete", data).then(function(result) {
                        return result;
                    });
                }

                //查询公共周期
                function timeslotstlUpdate(data) {
                    return requestApi("/rest/v1/timeslotstl/update", data).then(function(result) {
                        return result;
                    });
                }

                //创建项目
                function schematypeAdd(data) {
                    return requestApi("/rest/v1/schematype/add", data).then(function(result) {
                        return result;
                    });
                }


                //创建项目
                function schematypeDelete(data) {
                    return requestApi("/rest/v1/schematype/delete", data).then(function(result) {
                        return result;
                    });
                }

                //修改项目
                function schematypeUpdate(data) {
                    return requestApi("/rest/v1/schematype/update", data).then(function(result) {
                        return result;
                    });
                }

                //c查询项目
                function schematypeGet(data) {
                    return requestApi("/rest/v1/schematype/get", data).then(function(result) {
                        return result;
                    });
                }

                //c查询项目
                function stltodataAdd(data) {
                    return requestApi("/rest/v1/stltodata/add", data).then(function(result) {
                        return result;
                    });
                }

                //砍价统计查询
                function activityget(data) {
                    return requestApi('/rest/v1/bargainactivity/get', data).then(function(result) {
                        return result;
                    });
                }

                //c查询项目
                function schemaGet(data) {
                    return requestApi("/rest/v1/schema/get", data).then(function(result) {
                        return result;
                    });
                }
                //c添加项目
                function schemaAdd(data) {
                    return requestApi("/rest/v1/schema/add", data).then(function(result) {
                        return result;
                    });
                }

                //c修改项目
                function schemaUpdate(data) {
                    return requestApi("/rest/v1/schema/update", data).then(function(result) {
                        return result;
                    });
                }

                //c修改项目
                function schemaDelete(data) {
                    return requestApi("/rest/v1/schema/delete", data).then(function(result) {
                        return result;
                    });
                }


                //砍价统计查询
                function ffectget(data) {
                    return requestApi('/rest/v1/bargaineffect/get', data).then(function(result) {
                        return result;
                    });
                }

                //卡券
                function card(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    console.error("卡券列表--->", xdata);
                    // return false;
                    return requestApi('/rest/v1/wxproxy/get', xdata).then(function(result) {
                        return result;
                        // return resolve(result);
                    });
                }

                //批量上传小程序代码
                function batchUpload(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    xdata.method = "dhf.appedition.batchupload";

                    return requestApi('/rest/v1/php/dhf/batchupload/update', xdata).then(function(result) {
                        return result;
                    });

                }

                //批量查询小程序代码
                function batchGet(data) {
                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    xdata.method = "dhf.appedition.batchget";

                    return requestApi('/rest/v1/php/dhf/batchlog/get', xdata).then(function(result) {
                        return result;
                    });

                }

                //上传小程序代码
                function wxappUpload(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    xdata.method = "dhf.wxapp.upload";

                    return requestApi('/rest/v1/php/dhf/wxapp/upload', xdata).then(function(result) {
                        return result;
                    });

                }
                //公众号素材类目查询
                function gzhsucatGet(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/public/php/dhf/gzh/sucai/cat/get', xdata, 3600 * 24 * 30).then(function(result) {
                        return result;
                    });

                }

                //公众号素材类目添加
                function gzhsucatAdd(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    xdata.method = "gzh.sucai.cat.add";

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/cat/add', xdata).then(function(result) {
                        return result;
                    });

                }
                //公众号素材类目删除
                function gzhsucatDelete(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/cat/delete', xdata).then(function(result) {
                        return result;
                    });

                }

                //公众号素材类目删除
                function gzhsutagDelete(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/tag/delete', xdata).then(function(result) {
                        return result;
                    });

                }

                //公众号素材类目删除
                function gzhsutagAdd(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/tag/add', xdata).then(function(result) {
                        return result;
                    });

                }
                //公众号素材查询
                function gzhsutagGet(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/public/php/dhf/gzh/sucai/tag/get', xdata, 3600 * 24 * 30).then(function(result) {
                        return result;
                    });

                }

                function gzhscDelete(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/delete', xdata).then(function(result) {
                        return result;
                    });

                }

                //公众号素材
                function gzhscAdd(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/dhf/gzh/sucai/add', xdata).then(function(result) {
                        return result;
                    });

                }
                //公众号素材查询
                function gzhscGet(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/public/php/dhf/gzh/sucai/get', xdata).then(function(result) {
                        return result;
                    });

                }

                //上传小程序代码
                function wxappSubmit(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    xdata.method = "dhf.wxapp.submit";

                    return requestApi('/rest/v1/php/dhf/wxapp/submit', xdata).then(function(result) {
                        return result;
                    });

                }

                //上传小程序代码
                function wxappRelease(data) {

                    var xdata = clone(data);

                    xdata.content = angular.toJson(xdata.content);

                    data.method = "dhf.wxapp.release";

                    return requestApi('/rest/v1/php/dhf/wxapp/release', xdata).then(function(result) {
                        return result;
                    });

                }

                //下载卡券列表
                function cardidGet(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/cardid/get', xdata).then(function(result) {
                        return result;
                    });
                }



                //卡券列表
                function cardListGet(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/cardlist/get', xdata).then(function(result) {
                        return result;
                    });
                }

                //卡券领取列表
                function cardLogGet(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/cardlog/get', xdata).then(function(result) {
                        return result;
                    });
                }

                //卡券核销状态更改
                function cardLogUpdate(data) {
                    var xdata = clone(data);
                    xdata.content = angular.toJson(xdata.content);

                    return requestApi('/rest/v1/php/cardlog/update', xdata).then(function(result) {
                        return result;
                    });
                }

                //满就送列表
                function mjsGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.mjs.activity.get";

                    return requestApi("/rest/v1/php/dhf/mjs/activity/get", data).then(function(result) {
                        return result;
                    });
                }

                //满就送add
                function mjsAdd(data) {
                    var xdata = mjsData(data);
                    xdata.method = "dhf.mjs.activity.update";

                    return requestApi('/rest/v1/php/dhf/mjs/activity/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function mjsUpdate(data) {
                    var xdata = mjsData(data);
                    xdata.method = "dhf.mjs.activity.update";

                    return requestApi('/rest/v1/php/dhf/mjs/activity/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function mjsData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    var ddata = [];
                    ddata.content = angular.toJson(xdata);

                    return ddata;
                }

                function mjsItemGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.mjs.activity.item.get";

                    return requestApi("/rest/v1/php/dhf/mjs/activity/item/get", data).then(function(result) {
                        return result;
                    });
                }

                function mjsItemAdd(mjs_activity_id, item) {
                    var data = {
                        "content": {
                            // "store_id": $rootScope.store_id,
                            "mjs_activity_id": mjs_activity_id,
                            "item": JSON.stringify(item)
                        },
                        "method": "dhf.mjs.activity.item.add"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/mjs/activity/item/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function mjsItemDelete(id, mjs_activity_id) {
                    var data = {
                        "content": {
                            "id": id,
                            "mjs_activity_id": mjs_activity_id
                        },
                        "method": "dhf.mjs.activity.item.delete"
                    };

                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    return requestApi("/rest/v1/php/dhf/mjs/activity/item/delete", ddata).then(function(result) {
                        return result;
                    });
                }

                function mjsRangeGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.coupons.person.get";

                    return requestApi("/rest/v1/php/dhf/coupons/person/get", data).then(function(result) {
                        return result;
                    });
                }

                function mjsRangeAdd(data) {
                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    ddata.method = "dhf.coupons.person.get";

                    return requestApi("/rest/v1/php/dhf/coupons/person/add", ddata).then(function(result) {
                        return result;
                    });
                }

                function mjsRangeDelete(data) {
                    if (data.content) {
                        var ddata = clone(data);
                        ddata.content = angular.toJson(ddata.content);
                    }

                    ddata.method = "dhf.coupons.person.delete";

                    return requestApi("/rest/v1/php/dhf/coupons/person/delete", ddata).then(function(result) {
                        return result;
                    });
                }

                //分销商列表
                function distributorGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.distributor.get";
                    return requestApi("/rest/v1/php/fx/distributor/get", data).then(function(result) {
                        return result;
                    });
                }

                //更新分销商
                function distributorUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.distributor.update";
                    return requestApi("/rest/v1/php/fx/distributor/update", data).then(function(result) {
                        return result;
                    });
                }

                //分销订单
                function distributorOrderGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.detail.get";
                    return requestApi("/rest/v1/php/fx/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                //分销订单审核
                function distributorOrderUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);

                    }
                    data.method = "dhf.fx.detail.update";
                    return requestApi("/rest/v1/php/fx/detail/update", data).then(function(result) {
                        return result;
                    });
                }

                //结算记录
                function distributorClearingOrderGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.clearing.get";
                    return requestApi("/rest/v1/php/fx/clearing/get", data).then(function(result) {
                        return result;
                    });
                }

                //结算明细
                function distributorClearingDetailGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.clearing.detail.get";
                    return requestApi("/rest/v1/php/fx/clearing/detail/get", data).then(function(result) {
                        return result;
                    });
                }

                //结算记录审核
                function distributorClearingOrderUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);

                    }
                    data.method = "dhf.fx.clearing.status.update";
                    return requestApi("/rest/v1/php/fx/clearing/status/update", data).then(function(result) {
                        return result;
                    });
                }

                //分销商等级
                function fxgradeGet(data, nocache) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.grade.get";
                    return requestApi("/rest/v1/php/fx/grade/get", data, nocache ? 0 : 6000).then(function(result) {
                        return result;
                    });
                }

                //分销商等级添加
                function fxgradeAdd(data) {
                    if (data.content) {
                        data.content.store_id = $rootScope.store_id;
                        data.content.partner_id = sessionService.get('tokenUser').CompanyId;

                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.grade.update";

                    return requestApi("/rest/v1/php/fx/grade/update", data).then(function(result) {
                        return result;
                    });
                }

                //分销商等级更新
                function fxgradeUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.grade.update";
                    return requestApi("/rest/v1/php/fx/grade/update", data).then(function(result) {
                        return result;
                    });
                }

                //产品线列表
                function fxproductGet(data) {
                    if (data.content) {
                        data.content.store_id = $rootScope.store_id;

                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.get";
                    return requestApi("/rest/v1/php/fx/productcat/get", data).then(function(result) {
                        return result;
                    });
                }

                //产品线添加
                function fxproductAdd(data) {
                    if (data.content) {
                        data.content.store_id = $rootScope.store_id;
                        data.content.partner_id = sessionService.get('tokenUser').CompanyId;

                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.update";
                    return requestApi("/rest/v1/php/fx/productcat/update", data).then(function(result) {
                        return result;
                    });
                }

                //产品线编辑
                function fxproductUpdate(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.update";
                    return requestApi("/rest/v1/php/fx/productcat/update", data).then(function(result) {
                        return result;
                    });
                }

                //产品线商品
                function fxproductitemGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.item.get";
                    return requestApi("/rest/v1/php/fx/productcat/item/get", data).then(function(result) {
                        return result;
                    });
                }

                //产品线商品添加
                function fxproductItemAdd(data) {
                    if (data.content) {
                        data.content.store_id = $rootScope.store_id;
                        data.content.partner_id = sessionService.get('tokenUser').CompanyId;

                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.item.add";
                    return requestApi("/rest/v1/php/fx/productcat/item/add", data).then(function(result) {
                        return result;
                    });
                }

                //产品线商品删除
                function fxproductItemDelete(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.fx.productcat.item.delete";
                    return requestApi("/rest/v1/php/fx/productcat/item/delete", data).then(function(result) {
                        return result;
                    });
                }

                //清空所有缓存
                function removeAllCache() {
                    cacheService.destroy();
                    sessionService.removeAll();
                    return resolve();
                }

                //清空API请求缓存
                function removeDataCache() {
                    cacheService.destroy();
                    return resolve();
                }

                function attachGet(data) {
                    var xdata = data || {};
                    xdata.order_by = "id:desc";
                    if (xdata.mime) {
                        var x = xdata.mime.split(",");
                        _.map(x, function(a, i) {
                            if (['jpg', 'png', 'gif', 'jpeg'].indexOf(a) != -1) {
                                x[i] = "image/" + a;
                            }
                            if (['mp4'].indexOf(a) != -1) {
                                x[i] = "video/" + a;
                            }
                        });
                        xdata.mime = x.join(",");
                    }
                    return requestApi("/rest/v1/attach/get", data).then(function(result) {
                        //更换成相对路径
                        _.map(result.attachment, function(a) {
                            if (a.url.substr(0, 5) == "https") {
                                a.path = a.url;
                            } else {
                                a.path = ERP_CONFIG.attachUrl + a.url;
                            }
                            // a.path = a.path.replace("/static/uploads/", "../../../static/uploads/");
                        });
                        return result;
                    });
                }

                function attachDelete(data, method) {
                    var xdata = data || {};
                    return requestApi(method, xdata).then(function(result) {
                        return result;
                    });
                }

                function materialone(data) {
                    var xdata = data || {};
                    // xdata.order_by = "asc:desc";
                    return requestApi("/rest/v1/material/temp/get", data, 0, 'Get').then(function(result) {
                        //更换成相对路径
                        _.map(result.file, function(a) {
                            a.path = ERP_CONFIG.attachUrl + a.url;
                            // a.path = a.path.replace("/static/uploads/", "../../../static/uploads/");
                        });
                        return result;
                    });
                }

                function materialGet(data) {
                    var xdata = data || {};
                    // xdata.order_by = "asc:desc";
                    return requestApi("/rest/v1/material/uploadrecord/get", data).then(function(result) {
                        //更换成相对路径
                        _.map(result.file, function(a) {
                            a.path = ERP_CONFIG.attachUrl + a.url;
                            // a.path = a.path.replace("/static/uploads/", "../../../static/uploads/");
                        });
                        return result;
                    });
                }


                //管理员登录
                function isvLogin(user_name, password) {
                    return requestApi("/public/isv/login", {
                        user_name: user_name,
                        password: password
                    }).then(function(result) {
                        if (result.token) {
                            /*****************************
                             * Role的字段，数字类型： 1 表示买家 2 表示卖家 3 表示供应商 4 表示管理者
                             * 
                             ******************************/

                            var decoded = jwt_decode(result.token);

                            console.log("result.token:----", decoded);

                            decoded.CurrentUser.name = user_name;
                            sessionService.put("token", result.token);
                            sessionService.put("tokenUser", decoded.CurrentUser);
                            sessionService.put("currentUserInfo", decoded.CurrentUser);
                            sessionService.put("store", null);
                        }
                        return result;
                    });
                }

                //微信app版本获取
                function isvWxappOne(appid) {
                    return isvWxappGet({
                        query: {
                            appid: appid
                        }
                    }).then(function(result) {
                        if (result.wxapps && result.wxapps[0]) {
                            return result.wxapps[0];
                        } else {
                            return result;
                        }
                    });
                }

                //微信app版本获取
                function isvWxappGet(data) {
                    data = data || {};
                    var xdata = clone(data);
                    xdata.order_by = "appid:desc";
                    return requestApi("/rest/v1/wxapp/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //获取微信app版本
                function custaccountGet(data) {
                    data = data || {};
                    var xdata = clone(data);
                    xdata.order_by = xdata.order_by || "cust_account_id:desc";
                    return requestApi("/rest/v1/custaccount/get", xdata).then(function(result) {
                        return result;
                    });
                }



                //微信app版本获取
                function isvWxappAdd(data) {
                    return requestApi("/rest/v1/wxapp/add", data).then(function(result) {
                        return result;
                    });
                }

                //更新微信app版本获取
                function isvWxappUpdate(data) {

                    return requestApi("/rest/v1/wxapp/update", data).then(function(result) {
                        return result;
                    });
                }

                function balancelogGet(data) {
                    return requestApi("/rest/v1/balancelog/get", data).then(function(result) {
                        return result;
                    });
                }
                // 查询
                function reserveoptAdd(data) {
                    return requestApi("/rest/v1/reserveopt/add", data).then(function(result) {
                        return result;
                    });
                }
                //修改
                function reserveoptUpdate(data) {
                    return requestApi("/rest/v1/reserveopt/update", data).then(function(result) {
                        return result;
                    });
                }
                //查询 预约基础配置
                function reserveoptGet(data) {
                    return requestApi("/rest/v1/reserveopt/get", data).then(function(result) {
                        return result;
                    });
                }
                //预约单
                function preorderAdd(data) {
                    return requestApi("/rest/v1/preorder/add", data).then(function(result) {
                        return result;
                    });
                }

                function preorderGet(data) {
                    return requestApi("/rest/v1/preorder/get", data).then(function(result) {
                        return result;
                    });
                }

                function preordersGet(data) {
                    return requestApi("/rest/v1/preorders/get", data).then(function(result) {
                        return result;
                    });
                }

                //查询 新预约基础配置
                function preorderoptGet(data) {
                    return requestApi("/rest/v1/preorderopt/get", data).then(function(result) {
                        return result;
                    });
                }

                //生成数据
                function preorderoptAdd(data) {
                    return requestApi("/rest/v1/preorderopt/add", data).then(function(result) {
                        return result;
                    });
                }
                //修改数据
                function preoderoptUpdate(data) {
                    return requestApi("/rest/v1/preorderopt/update", data).then(function(result) {
                        return result;
                    });
                }

                function resitemUpdate(data) {
                    return requestApi("/rest/v1/resitem/update", data).then(function(result) {
                        return result;
                    });
                }
                //预约数据
                function periodsGet(data) {
                    return requestApi("/rest/v1/periods/get", data).then(function(result) {
                        return result;
                    });
                }

                function periodsUpdate(data) {
                    return requestApi("/rest/v1/periods/update", data).then(function(result) {
                        return result;
                    });
                }

                function periodsDelete(data) {
                    return requestApi("/rest/v1/periods/delete", data).then(function(result) {
                        return result;
                    });
                }

                function templatetodataAdd(data) {
                    return requestApi("/rest/v1/templatetodata/add", data).then(function(result) {
                        return result;
                    });
                }

                function resitemAdd(data) {
                    return requestApi("/rest/v1/resitem/add", data).then(function(result) {
                        return result;
                    });
                }


                function resitemDelete(data) {
                    return requestApi("/rest/v1/resitem/delete", data).then(function(result) {
                        return result;
                    });
                }


                function periodsPublic(data) {
                    return requestApi("/rest/v1/periods/public/update/", data).then(function(result) {
                        return result;
                    });
                }

                function resitemGet(data) {
                    return requestApi("/rest/v1/resitem/get", data).then(function(result) {
                        return result;
                    });
                }

                //查询新预约时间数据
                function templateGet(data) {
                    return requestApi("/rest/v1/template/get", data).then(function(result) {
                        return result;
                    });
                }

                function templateAdd(data) {
                    return requestApi("/rest/v1/template/download/add", data).then(function(result) {
                        return result;
                    });
                }

                function templateUpdate(data) {
                    return requestApi("/rest/v1/template/update", data).then(function(result) {
                        return result;
                    });
                }

                function templateDelete(data) {
                    return requestApi("/rest/v1/template/delete", data).then(function(result) {
                        return result;
                    });
                }

                //预约数据类目
                function restypeAdd(data) {
                    return requestApi("/rest/v1/restype/add", data).then(function(result) {
                        return result;
                    });
                }

                function restypeUpdate(data) {
                    return requestApi("/rest/v1/restype/update", data).then(function(result) {
                        return result;
                    });
                }

                function restypeDelete(data) {
                    return requestApi("/rest/v1/restype/delete", data).then(function(result) {
                        return result;
                    });
                }

                function restypeGet(data) {
                    return requestApi("/rest/v1/restype/get", data).then(function(result) {
                        return result;
                    });
                }

                // 小店的查询
                function ministoreGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.ministore.list";
                    return requestApi("/rest/v1/php/ministore/list", data).then(function(result) {
                        return result;
                    });
                }

                function ministoreUpdete(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.ministore.update";
                    return requestApi("/rest/v1/php/ministore/update", data).then(function(result) {
                        return result;
                    });
                }

                function ministoreAdd(data) {

                    return requestApi("/rest/v1/php/proxy/add", data).then(function(result) {
                        return result;
                    });
                }

                //订单个数统计
                function ordercountGet(xdata) {
                    if (xdata.content) {
                        var data = clone(xdata);
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.analysis.order.total.count";
                        return requestApi("/rest/v1/php/analysis/ordercount/get", data, 24 * 3600).then(function(result) {
                            return result;
                        });
                    }
                }
                // orderamountGet
                function orderamountGet(xdata) {
                    if (xdata.content) {
                        var data = clone(xdata);
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.analysis.order.total.amount";
                        return requestApi("/rest/v1/php/analysis/orderamount/get", data, 24 * 3600).then(function(result) {
                            return result;
                        });
                    }
                }

                //拼团的查询
                function pintuanGet(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                        data.method = "dhf.pintuan.get";
                        return requestApi("/rest/v1/php/dhf/pintuan/get", data).then(function(result) {
                            return result;
                        });
                    }
                }

                //拼团的添加
                function pintuanAdd(data) {
                    var ddata = pintuanData(data);
                    ddata.method = "dhf.pintuan.add";
                    return requestApi("/rest/v1/php/dhf/pintuan/add", ddata).then(function(result) {
                        return result;
                    });

                }

                //拼团的修改
                function pintuanUpdate(data) {
                    var ddata = pintuanData(data);
                    ddata.method = "dhf.pintuan.update";
                    return requestApi("/rest/v1/php/dhf/pintuan/update", ddata).then(function(result) {
                        return result;
                    });
                }


                //拼团详情 dhf.pintuan.activity.get
                function pintuanactivityGet(data) {
                    var ddata = [];
                    ddata.content = angular.toJson(data.content);
                    ddata.method = "dhf.pintuan.activity.get";

                    return requestApi("/rest/v1/php/dhf/pintuan/activity/get", ddata).then(function(result) {
                        return result;
                    });
                }

                //拼团顾客数据 dhf.pintuan.detil.get
                function pintuandetilGet(data) {
                    var ddata = [];
                    ddata.content = angular.toJson(data.content);
                    ddata.method = "dhf.pintuan.detail.get";
                    return requestApi("/rest/v1/php/dhf/pintuan/detail/get", ddata).then(function(result) {
                        return result;
                    });
                }


                function pintuanData(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }
                    var ddata = [];
                    ddata.content = angular.toJson(xdata);
                    return ddata;
                }

                //拼团的删除
                function pintuanDelete(data) {
                    if (data.content) {
                        data.content = angular.toJson(data.content);
                    }
                    data.method = "dhf.pintuan.update";
                    return requestApi("/rest/v1/php/dhf/pintuan/delete", data).then(function(result) {
                        return result;
                    });
                }

                //充值活动查询
                function balanceGet(data) {
                    return requestApi("/rest/v1/chargeactivity/get", data).then(function(result) {
                        return result;
                    });
                }

                //充值活动添加
                function balanceAdd(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi("/rest/v1/chargeactivity/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //充值活动更新
                function balanceUpdate(data) {
                    var xdata = clone(data);
                    if (xdata.start_time && xdata.end_time) {
                        xdata.start_time = toStdTime(xdata.start_time);
                        xdata.end_time = toStdTime(xdata.end_time);
                    }

                    return requestApi("/rest/v1/chargeactivity/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //充值活动删除
                function balanceDelete(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/chargeactivity/delete", xdata).then(function(result) {
                        return result;
                    });
                }

                //微信app版本获取
                function isvWxappDelete(appid) {
                    return requestApi("/rest/v1/wxapp/delete", {
                        appid: appid
                    }).then(function(result) {
                        return result;
                    });
                }
                //请求售后
                function serviceUpdate(data) {
                    return requestApi("/rest/v1/order/service/update", data).then(function(result) {
                        return result;
                    });
                }

                //上传代码
                function isvCodeCommitAdd(store_id, authorizer_appid, template_id, ext_json, user_version, user_desc) {
                    var data = {
                        authorizer_appid: authorizer_appid,
                        template_id: template_id,
                        ext_json: angular.toJson(ext_json),
                        user_version: user_version,
                        user_desc: user_desc,
                    };

                    return requestApi("/rest/v1/code/commit/add", data).then(function(result) {
                        if (result.code == 0) {
                            return saveStoreCodeStatus(store_id, authorizer_appid, {
                                template_id: template_id
                            });
                        } else {
                            helper.myAlert(result.Msg);
                            return reject();
                        }
                    });
                }

                //获取门店当前开发版
                function getStoreCodeStatus(store_id, authorizer_appid) {
                    // "storre_code_status_" + store_id + "_" + authorizer_appid
                    return shopConfigOneByKey("store_code_status_" + authorizer_appid).then(function(a) {
                        if (a) {
                            return JSON.parse(a.value);
                        } else {
                            return shopConfigOneByKey("store_code_status_" + store_id + "_" + authorizer_appid).then(function(a) {
                                if (a) {
                                    return JSON.parse(a.value);
                                }
                            });
                        }
                    });
                }

                //保存门店当前开发版
                function saveStoreCodeStatus(store_id, authorizer_appid, data) {
                    // var field = "store_code_status_" + store_id + "_" + authorizer_appid;
                    var field = "store_code_status_" + authorizer_appid;
                    return shopConfigOneByKey(field).then(function(a) {
                        console.log("查询到shopconfig======", a, "更新进入的参数：", data);
                        if (a) {
                            a.value = JSON.parse(a.value);
                            _.map(data, function(v, k) {
                                a.value[k] = v;
                            });
                            //                             console.log("update到shopconfig======", a)
                            return shopConfigUpdate(a);
                        } else {
                            return shopConfigAdd({
                                field: field,
                                value: data
                            });
                        }
                    });
                }

                //设置体验者
                function isvTesterAdd(authorizer_appid, wechatid) {
                    return requestApi("/rest/v1/tester/add", {
                        authorizer_appid: authorizer_appid,
                        wechatid: wechatid
                    }).then(function(result) {
                        if (Number(result.code) === 0 || (result.Msg && result.Msg.indexOf("user already bind"))) {
                            return testerSave(authorizer_appid, wechatid).then(function() {
                                return true;
                            });
                        } else if (result.Msg) {
                            helper.myAlert("错误：" + result.Msg);
                        }
                    });
                }




                //解除体验者
                function isvTesterDelete(authorizer_appid, wechatid) {
                    return requestApi("/rest/v1/tester/delete", {
                        authorizer_appid: authorizer_appid,
                        wechatid: wechatid
                    }).then(function(result) {
                        if (result.code == 0) {
                            return testerSave(authorizer_appid, wechatid, true).then(function() {
                                return true;
                            });
                        } else {
                            return result;
                        }
                    });
                }

                //获取体验二维码
                function isvCodeQrcodeGet(authorizer_appid) {
                    return requestApi("/rest/v1/code/qrcode/get", {
                        authorizer_appid: authorizer_appid,
                        base64: true
                    }, 0, "get").then(function(result) {
                        return result;
                    });
                }

                //提交代码审核
                function codeSubmitAuditAdd(store_id, authorizer_appid, data, template_id) {
                    return requestApi("/rest/v1/code/submit_audit/add", {
                        authorizer_appid: authorizer_appid,
                        data: angular.toJson(data)
                    }).then(function(result) {
                        // console.error("--------result:", result);
                        // result = { code: 0, auditid: 436244237 } // wx5d5ffdcf11270090
                        // var a = { code: 0, auditid: 598743349 };
                        if (result.auditid) {
                            saveStoreCodeStatus(store_id, authorizer_appid, {
                                auditid: result.auditid,
                                submit_template_id: template_id
                            });
                        }
                        return result;
                    });
                }

                //获取审核状态
                function codeAuditStatusGet(authorizer_appid, audit_id) {
                    return requestApi("/rest/v1/code/auditstatus/get", {
                        authorizer_appid: authorizer_appid,
                        audit_id: audit_id
                    }).then(function(result) {
                        return result;
                    });
                }

                //==========================================================================
                //发布代码
                function codeReleaseAdd(store_id, authorizer_appid) {
                    return requestApi("/rest/v1/code/release/add", {
                        authorizer_appid: authorizer_appid
                    }).then(function(result) {
                        try {
                            var a = JSON.parse(result.Msg);
                            console.log("--------发布结果:", a);
                            // a.code = 0;
                            if (a.code == 0) {
                                saveStoreCodeStatus(store_id, authorizer_appid, {
                                    publishstatus: 1
                                });
                            }
                            return a;
                        } catch (e) {
                            return result;
                        }
                    });
                }
                //==========================================================================
                //可见状态
                function codeChangeStatusUpdate(store_id, authorizer_appid, action) {
                    return requestApi("/rest/v1/code/changestatus/update", {
                        authorizer_appid: authorizer_appid,
                        action: action
                    }).then(function(result) {
                        try {
                            var a = JSON.parse(result.Msg);
                            console.log("--------发布结果:", a);
                            // a.code = 0;
                            if (a.code == 0) {
                                return saveStoreCodeStatus(store_id, authorizer_appid, {
                                    visiblestatus: action
                                });
                            } else {
                                return a;
                            }
                        } catch (e) {
                            return result;
                        }
                    });
                }
                //==========================================================================


                //保存tester
                function testerSave(authorizer_appid, wechatid, isDelete) {
                    var xkey = authorizer_appid + "_tester";
                    return testerGet(authorizer_appid).then(function(all) {
                        if (all) {
                            if (isDelete) {
                                all.value = _.difference(all.value, [wechatid]);
                                return shopConfigUpdate(all);
                            } else if (all.value.indexOf(wechatid) == -1) {
                                all.value.push(wechatid);
                                return shopConfigUpdate(all);
                            }
                        } else {
                            return shopConfigAdd({
                                field: xkey,
                                value: [wechatid]
                            });
                        }
                    });
                }
                //获取tester
                function testerGet(authorizer_appid) {
                    var xkey = authorizer_appid + "_tester";
                    return shopConfigOneByKey(xkey).then(function(a) {
                        if (a && a.value) {
                            a.value = JSON.parse(a.value);
                            return a;
                        } else {
                            return null;
                        }
                    });
                }

                //获取已登录的用户
                function currentLoginedUser() {
                    var user = sessionService.get("currentUserInfo");
                    if (user) {
                        return user;
                    } else {
                        $rootScope.$broadcast("event:auth-loginRequired");
                        return {};
                    }
                }

                //获取用户登录信息
                function userCurrentGet(getCache) {

                    if (getCache) {
                        var cacheInfo = sessionService.get('currentUserInfo');
                        if (cacheInfo) {
                            return resolve(cacheInfo);
                        }
                    }

                    var tokenUser = sessionService.get("tokenUser") || {};

                    var Role = tokenUser["Role"];
                    //                     console.log("------Role", Role);

                    if (Role == 3) {
                        var mm = supplierUserCurrentGet;
                    } else if (Role == 2) {
                        var mm = sellerUserCurrentGet;
                    } else if (Role == 4) {
                        return resolve(tokenUser);
                    } else {
                        $rootScope.$broadcast('event:auth-loginRequired');
                        return reject();
                    }
                    return mm().then(function(result) {
                        console.log("currentUserInfo", result)
                        sessionService.put('currentUserInfo', result);
                        return result;
                    });
                }

                //退出
                function logout() {
                    var tokenUser = sessionService.get("tokenUser") || {};
                    console.log("tokenUser", tokenUser);
                    var userType = tokenUser["Role"];
                    var api = '';
                    if (userType == 1) {
                        api = '/rest/supplier/user/logout';
                    } else if (userType == 2) {
                        api = '/rest/v1/seller/logout';
                    } else {
                        api = '/rest/buyer/user/logout';
                    }
                    return requestApi(api).then(function(result) {
                        sessionService.removeAll();
                        return result;
                    });
                }

                //登录动作
                function login(name, pwd, company_id) {
                    return requestApi("/login/", {
                        company_id: company_id,
                        user_name: name,
                        password: pwd
                    }).then(function(result) {
                        // console.error("result", result);
                        return result;
                    });
                }

                //加载模板
                function tpl(url) {
                    return $http.get(url).then(function(result) {
                        //return 
                        if (result && result.data) {
                            return result.data;
                        } else {
                            return 'none template';
                        }
                    });
                }

                //用户列表
                function userGet(data, ttl) {
                    ttl = _.isNumber(ttl) ? ttl : 10 * 60
                    data.order_by = "created_at:desc";
                    return requestApi("/rest/user/get", data, ttl).then(function(result) {
                        return result;
                    });
                }

                //获取1个用户
                function userOne(user_id) {
                    if (!user_id) {
                        return reject("user_id为空");
                    }

                    var cache = oneCacheGet("userOne", user_id);
                    if (cache !== false) {
                        return cache;
                    }

                    return userGet({
                        query: {
                            "user_id": user_id
                        }
                    }).then(function(result) {
                        if (result.total_count == 1) {
                            return oneCacheSet("userOne", user_id, result.users[0]);
                        } else {
                            return reject("未找到id：" + user_id + "的数据");
                        }
                    });
                }

                function getToken(cb) {
                    var token = sessionService.get('token');
                    if (token) {
                        cb(token);
                    } else {
                        //   console.log("缺少token，需要登录！");
                        $rootScope.login();
                    }
                }

                //供应商注册
                function supplierRegister(data) {
                    return requestApi("/public/supplier/register", data).then(function(result) {
                        return result;
                    });
                }

                //供应商登录
                function supplierLogin(name, password) {
                    return requestApi("/public/supplier/login", {
                        user_name: name,
                        password: password
                    }).then(function(result) {
                        return result;
                    });
                }

                //供应商当前用户
                function supplierUserCurrentGet() {
                    return requestApi("/rest/supplier/user/current/get").then(function(result) {
                        return result;
                    });
                }

                //分销商注册
                function sellerRegister(data) {
                    return requestApi("/public/seller/register", data).then(function(result) {
                        return result;
                    });
                }

                //分销商登录
                function sellerLogin(name, password, selpartner_id) {
                    return requestApi("/public/seller/login", {
                        user_name: name,
                        password: password,
                        partner_id: selpartner_id,
                    }).then(function(result) {
                        if (result.token) {
                            /*****************************
                             * Role的字段，数字类型： 1 表示买家 2 表示卖家 3 表示供应商 4 表示管理者
                             * 
                             ******************************/
                            var decoded = jwt_decode(result.token);
                            console.log("result.token:----", decoded);
                            decoded.CurrentUser.name = name;
                            sessionService.put("token", result.token);
                            sessionService.put("tokenUser", decoded.CurrentUser);
                            sessionService.put("currentUserInfo", decoded.CurrentUser);
                            sessionService.put("store", null);
                        }
                        return result;
                    });
                }

                //A小程序二维码---直达页面 : 接口A加上接口C，总共生成的码数量限制为100,000，请谨慎调用。
                function acodeGet(authorizer_appid, cpath, isBase64, getUrl) {
                    isBase64 = isBase64 ? true : false;
                    var path = "/rest/v1/acode/get";
                    var token = sessionService.get('token');
                    var p = {
                        authorizer_appid: authorizer_appid,
                        path: cpath,
                        base64: isBase64,
                        token: token,
                        r: 0,
                        b: 0,
                        g: 0
                    };
                    var url = ERP_CONFIG.apiUrl + path + "?" + buildQuery(p);
                    if (getUrl) {
                        return url;
                    }

                    return requestApi(path, p, 0, "GET").then(function(image) {
                        if (image.length < 200) {
                            var code = base64.decode(image);
                            console.error("出错了：", code);
                        } else {
                            return image;
                        }
                    });
                }

                //B小程序二维码---直达首页，数量没有限制
                function acodeunlimitGet(authorizer_appid, scene, isBase64, page, getUrl, ttl) {
                    isBase64 = isBase64 ? true : false;
                    page = page || "pages/index/index";
                    var path = "/public/acodeunlimit/get";
                    var token = sessionService.get('token');
                    var p = {
                        authorizer_appid: authorizer_appid,
                        scene: scene,
                        base64: isBase64,
                        page: page,
                        auto_color: false,
                        width: "600",
                        r: 0,
                        g: 0,
                        b: 0
                    };
                    var url = ERP_CONFIG.apiUrl + path + "?" + buildQuery(p);
                    if (getUrl) {
                        return url;
                    }
                    var cache_time = ttl ? ttl : 0;
                    return requestApi(path, p, cache_time, "GET").then(function(image) {
                        if (image.length < 200) {
                            var code = base64.decode(image);
                            console.error("出错了：", code, url);
                            return;
                        } else {
                            return image;
                        }
                    });
                }

                //C小程序二维码---直达页面 : 接口A加上接口C，总共生成的码数量限制为100,000，请谨慎调用。
                function aqrcodeGet(authorizer_appid, path, isBase64, getUrl) {
                    isBase64 = isBase64 ? true : false;
                    var path = "/rest/v1/aqrcode/get";
                    var token = sessionService.get('token');
                    var p = {
                        authorizer_appid: authorizer_appid,
                        path: path,
                        base64: isBase64,
                        token: token
                    };
                    var url = ERP_CONFIG.apiUrl + path + "?" + buildQuery(p);
                    if (getUrl) {
                        return url;
                    }

                    return requestApi(path, p, 0, "GET").then(function(image) {
                        if (image.length < 200) {
                            var code = base64.decode(image);
                            console.error("出错了：", code);
                        } else {
                            return image;
                        }
                    });
                }
                //修改用户信息
                function sellerUserUpdate(data) {
                    return requestApi("/rest/v1/seller/update", data).then(function(result) {
                        return result;
                    });
                }
                //分销商当前用户
                function sellerUserCurrentGet() {
                    return requestApi("/rest/v1/seller/current/get").then(function(result) {
                        return result;
                    });
                }
                //行政区查询
                function areaGet(data) {
                    var ttl = 365 * 24 * 60 * 60;
                    var xdata = clone(data);
                    xdata.order_by = "area_id:asc";
                    return requestApi("/public/area/get", xdata).then(function(result) {
                        return result;
                    });
                }

                function areaGetById(id) {
                    var deferred = $q.defer();
                    getAllCity(function(citys) {
                        console.log("$rootScope.citys", citys);
                        deferred.resolve(citys[id]);
                    });
                    return deferred.promise;
                }
                //支付配置添加
                function payConfigAdd(data) {
                    var xdata = clone(data);
                    return requestApi('/rest/v1/payparams/add', xdata).then(function(result) {
                        return result;
                    });
                }

                function payConfigUpdate(data) {
                    var xdata = clone(data)
                    return requestApi('/rest/v1/payparams/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function payConfigGet(cust_account_id) {
                    var query = {
                        query: {
                            "cust_account_id": cust_account_id
                        }
                    }
                    return requestApi('/rest/v1/payparams/get', query).then(function(result) {
                        if (result && result.pay_params && result.pay_params.length == 1)
                            return result.pay_params[0];
                    });
                }
                //分销产品先新增
                function productcatAdd(data) {
                    var xdata = clone(data);
                    return requestApi('/rest/supplier/productcat/add', xdata).then(function(result) {
                        return result;
                    });
                }
                //分销产品线查询
                function productcatGet(data) {
                    var xdata = clone(data) || {};
                    xdata.order_by = "id:desc";
                    return requestApi("/rest/supplier/productcat/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //删除产品线
                function productcatOne(id) {
                    if (id) {
                        var query = {
                            "id": id
                        };
                    }
                    return productcatGet({
                        query: query
                    }).then(function(result) {
                        if (result.shop) {
                            return result.shop[0];
                        } else {
                            return reject("没有找到产品线");
                        }
                    });
                }
                //修改产品线
                function productcatUpdate(data) {
                    var xdata = clone(data);
                    return requestApi('/rest/supplier/productcat/update', xdata).then(function(result) {
                        return result;
                    });
                }

                function productcatDelete(id) {
                    return requestApi("/rest/supplier/productcat/delete", {
                        id: id
                    }).then(function(result) {
                        return result;
                    });
                }
                //分销产品发布(查询)
                function supllerProductGet(data) {
                    var xdata = clone(data) || {};
                    xdata.order_by = "pid:desc";
                    return requestApi("/rest/supplier/product/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销产品单个查询
                function supllerProductOne(pid) {
                    if (pid) {
                        var query = {
                            "pid": pid
                        };
                    }
                    return supllerProductGet({
                        query: query
                    }).then(function(result) {
                        if (result.shop) {
                            return result.shop[0];
                        }
                    });
                }
                //分销产品发布(新增)
                function supllerProductAdd(data) {
                    var xdata = clone(data);
                    xdata.skus = angular.toJson({
                        "skus": xdata.skus
                    });
                    return requestApi("/rest/supplier/product/add", xdata).then(function(result) {
                        return result;
                    });
                }
                /*************************王苍 start*****************************************************/

                //分销产品发布(删除)
                function supllerProductDelete(pid) {

                    return requestApi("/rest/supplier/product/delete", {
                        pid: pid
                    }).then(function(result) {
                        return result;
                    });
                }
                //分销产品发布(编辑)
                function supllerProductUpdate(data) {
                    var xdata = clone(data);
                    xdata.skus = angular.toJson({
                        "skus": xdata.skus
                    });
                    // var xdatas={pid:xdata.pid,product:xdata}
                    return requestApi("/rest/supplier/product/update", xdata).then(function(result) {
                        return result;
                    });
                }

                ///
                //分销产品发布(上架)
                function supllerProductShowUpdate(pid) {
                    return requestApi("/rest/supplier/product/show/update", {
                        pid: pid
                    }).then(function(result) {
                        return result;
                    });
                }

                //分销产品发布(下架)
                function supllerProductUnshowUpdate(pid) {
                    return requestApi("/rest/supplier/product/unshow/update", {
                        pid: pid
                    }).then(function(result) {
                        return result;
                    });
                }
                //设置分销商查询
                function partnerGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "partner_id:desc";
                    return requestApi("/rest/supplier/partner/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //单个设置分销商查询
                function partnerOne(partner_id) {
                    return partnerGet({
                        query: {
                            "partner_id": partner_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop ? result.shop[0] : result.shop;
                        }
                    });

                }
                //设置分销商添加
                function partnerAdd(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/partner/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //设置分销商修改
                function partnerUpdate(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/partner/update", xdata).then(function(result) {
                        return result;
                    });
                }
                //设置分销商删除
                function partnerDelete(partner_id) {
                    return requestApi("/rest/supplier/partner/delete", {
                        partner_id: partner_id
                    }).then(function(result) {
                        return result;
                    });
                }
                //分销商等级管理查询
                function fenxiaogradeGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "grade_id:desc";
                    return requestApi("/rest/supplier/fenxiaograde/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //单个分销商等级管理查询
                function fenxiaogradeOne(grade_id) {
                    return fenxiaogradeGet({
                        query: {
                            "grade_id": grade_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });
                }
                //分销商等级添加
                function fenxiaogradeAdd(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/fenxiaograde/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销商等级修改
                function fenxiaogradeUpdate(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/fenxiaograde/update", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销商等级删除
                function fenxiaogradeDelete(grade_id) {
                    return requestApi("/rest/supplier/fenxiaograde/delete", {
                        grade_id: grade_id
                    }).then(function(result) {
                        return result;
                    });
                }

                //分销价格管理查询
                function fenxiaopriceGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "id:desc";
                    return requestApi("/rest/supplier/fenxiaoprice/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //单个分销价格管理查询
                function fenxiaopriceOne(id) {
                    return fenxiaopriceGet({
                        query: {
                            "id": id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });

                }
                //分销价格添加
                function fenxiaopriceAdd(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/fenxiaoprice/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销价格修改
                function fenxiaopriceUpdate(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/fenxiaoprice/update", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销价格删除
                function fenxiaopriceDelete(id) {
                    return requestApi("/rest/supplier/fenxiaoprice/delete", {
                        id: id
                    }).then(function(result) {
                        return result;
                    });
                }
                //分销合作关系管理查询
                function supplerCooperationGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "cooperate_id:desc";
                    return requestApi("/rest/supplier/cooperation/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //单个分销合作关系管理查询
                function supplerCooperationOne(cooperate_id) {
                    return supplerCooperationGet({
                        query: {
                            "cooperate_id": cooperate_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });

                }
                //分销合作关系添加
                function supplerCooperationAdd(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/cooperation/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //分销合作关系修改
                function supplerCooperationUpdate(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/cooperation/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //分销合作关系删除
                function supplerCooperationDelete(cooperate_id) {
                    return requestApi("/rest/supplier/cooperation/delete", {
                        cooperate_id: cooperate_id
                    }).then(function(result) {
                        return result;
                    });
                }

                //运费模板查询
                function faretempGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "fare_id:desc";
                    return requestApi("/rest/supplier/faretemp/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //运费模板单一查询
                function faretempOne(fare_id) {
                    return faretempGet({
                        query: {
                            "fare_id": fare_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.fare_temp[0];
                        }
                    });
                }

                //运费模板添加
                function faretempAdd(data) {
                    var xdata = clone(data);
                    // return async.map(xdata.carry_modes,function(carry_mode,callback){
                    //      delete carry_mode["regionObj"];
                    //      callback(null,null)
                    //  },function(e,r){
                    xdata.carry_modes = angular.toJson({
                        "carry_modes": xdata.carry_modes
                    });
                    return requestApi("/rest/supplier/faretemp/add", xdata).then(function(result) {
                        return result;
                    });
                    // });

                }

                //运费模板删除
                function faretempDelete(fare_id) {
                    return requestApi("/rest/supplier/faretemp/delete", {
                        fare_id: fare_id
                    }).then(function(result) {
                        return result;
                    });
                }

                //运费模板修改
                function faretempUpdate(data) {
                    var xdata = clone(data);
                    xdata.carry_modes = angular.toJson({
                        "carry_modes": xdata.carry_modes
                    });
                    // var xdatas={fare_id:xdata.fare_id,template:xdata}
                    return requestApi("/rest/supplier/faretemp/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //订单发货
                function orderDeliverGoods(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/supplier/order/status/update", xdata).then(function(result) {
                        return result;
                    })
                }

                //订单售后流转
                function orderDeliverGoods(return_form_id, event) {

                    return requestApi("/rest/supplier/returnform/status/update", xdata).then(function(result) {
                        return result;
                    })
                }

                //财务管理查询
                function accountGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "member_id:desc";
                    return requestApi("/rest/supplier/account/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //财务管理
                function accountOne(member_id) {
                    return accountGet({
                        query: {
                            "member_id": member_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });
                }

                // 
                //会员帐号值
                function memberAccountGet(data) {
                    var xdata = clone(data);
                    return requestApi("/rest/v1/account/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //分销商绩效查询
                function profitGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "partner_id:desc";
                    return requestApi("/rest/supplier/profit/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //分销商绩效查询
                function profitOne(partner_id) {
                    return profitGet({
                        query: {
                            "partner_id": partner_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });

                }

                //售后统计表查询
                function returnreportGet(data) {
                    var xdata = clone(data);
                    xdata.order_by = "partner_id:desc";
                    return requestApi("/rest/supplier/returnreport/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //售后统计表查询
                function returnreportOne(partner_id) {
                    return profitGet({
                        query: {
                            "partner_id": partner_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.shop[0];
                        }
                    });

                }

                //查询店铺
                function storeGet(data, cache) {
                    var xdata = clone(data);
                    xdata = xdata || {};
                    return requestApi("/rest/v1/store/get", xdata, cache ? 600 : 0).then(function(result) {
                        return result;
                    });
                }

                //查询店铺
                function storeOne(store_id, cache) {
                    return storeGet({
                        query: {
                            store_id: store_id
                        }
                    }, cache).then(function(result) {
                        if (result.store) {
                            return result.store[0];
                        }
                    });
                }

                //查询店铺
                function storeAdd(data) {
                    return requestApi("/rest/v1/store/add", data).then(function(result) {
                        return result;
                    });
                }

                //更新店铺
                function storeUp(data) {
                    return requestApi("/rest/v1/store/update", data).then(function(result) {
                        return result;
                    });
                }

                //类目显示
                function categoryGet(data, nocache) {
                    return requestApi("/rest/v1/category/get", data, (nocache >= 0) ? nocache : 24 * 3600).then(function(result) {
                        return result;
                    });
                }

                //类目添加
                function categoryAdd(data) {
                    return requestApi("/rest/v1/category/add", data).then(function(result) {
                        return result;
                    });
                }

                //类目修改
                function categoryUpdate(data) {
                    return requestApi("/rest/v1/category/update", data).then(function(result) {
                        return result;
                    });
                }

                //类目删除
                function categoryDelete(data) {
                    return requestApi("/rest/v1/category/delete", data).then(function(result) {
                        return result;
                    });
                }
                //商品列表
                function itemGet(data, name) {
                    var xdata = data || {};
                    xdata.order_by = "item_id:desc";
                    xdata.fields = "";
                    return requestApi("/rest/v1/item/get", xdata).then(function(result) {
                        return result;
                    });
                }
                //商品列表
                function itemOne(item_id) {
                    return itemGet({
                        query: {
                            "item_id": item_id
                        }
                    }).then(function(result) {
                        if (result && result.items) {
                            return oneCacheSet("itemOne", item_id, result.items[0]);
                        } else {
                            return reject("未找到item_id：" + item_id);
                        }
                    });
                }
                //sku_id查询
                function itemSkuOne(item_id, sku_id) {
                    // console.log("sdlkfsdfsdf", item_id, sku_id);
                    return itemOne(item_id).then(function(b) {
                        if (sku_id && b) {
                            _.map(b.skus, function(c) {
                                if (c.sku_id == sku_id) {
                                    b.sku = c;
                                }
                            });
                        }
                        return b;
                    })
                }
                //商品增加
                function itemAdd(data) {
                    var xdata = clone(data);
                    // xdata = itemFloat32(xdata);
                    xdata.skus = angular.toJson({
                        "skus": xdata.skus
                    });
                    return requestApi("/rest/v1/item/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //商品更新
                function itemUpdate(data) {
                    var xdata = clone(data);
                    // xdata = itemFloat32(xdata);
                    if (xdata.skus) {
                        xdata.skus = angular.toJson({
                            "skus": xdata.skus
                        });
                    }

                    delete xdata.updated_at;
                    delete xdata.created_at;
                    delete xdata.company_id;
                    if (xdata.p_item_id) {
                        delete xdata.p_item_id;
                    }
                    // xdata.description = helper.phtml(xdata.description);

                    return requestApi("/rest/v1/item/update", xdata).then(function(result) {
                        if (result.item_id) {
                            oneCacheDel("itemOne", result.item_id);
                        }
                        return result;
                    });
                }
                //商品sku删除
                function itemDelete(data) {
                    return requestApi("/rest/v1/item/delete", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku增加
                function itemSkuAdd(data) {
                    var xdata = clone(data);
                    console.log(data);
                    return requestApi("/rest/v1/skutype/add", xdata).then(function(result) {
                        return result;
                    });
                }
                //商品sku修改
                function itemSkuUpdate(data) {
                    var xdata = clone(data);
                    // xdata.sku =angular.toJson(data.skus);
                    return requestApi("/rest/v1/skutype/update", xdata).then(function(result) {
                        return result;
                    })
                }

                //激活停用商品
                function itemStatusUpdate(item_id, status_id, sku_id) {
                    return requestApi("/rest/v1/item/status/update", {
                        item_id: item_id,
                        status_id: status_id,
                        sku_id: sku_id
                    }).then(function(result) {
                        if (result.item_id) {
                            return true;
                        } else {
                            return reject(result.Msg);
                        }
                    });
                }

                //停用商品
                function disableUpdate(data) {
                    return requestApi("/rest/v1/seller/disable/update", data).then(function(result) {
                        if (result.user_id) {
                            return true;
                        } else {
                            return reject(result.Msg);
                        }
                    });
                }

                //激活商品
                function enableUpdate(data) {
                    return requestApi("/rest/v1/seller/enable/update", data).then(function(result) {
                        if (result.user_id) {
                            return true;
                        } else {
                            return reject(result.Msg);
                        }
                    });
                }

                //激活停用商品
                function itemSkuStatusUpdate(sku_id, status_id) {
                    return requestApi("/rest/v1/item/sku/status/update", {
                        sku_id: sku_id,
                        status_id: status_id
                    }).then(function(result) {
                        if (result.sku_id) {
                            return true;
                        } else {
                            return reject(result.Msg);
                        }
                    });
                }

                //查询订单
                function orderGet(data) {
                    var xdata = data || {};
                    xdata.order_by = "created_at:desc";
                    return requestApi("/rest/v1/order/get", xdata).then(function(result) {
                        return result;
                    });
                }

                //d订单
                function orderOne(order_id) {
                    return orderGet({
                        query: {
                            order_id: order_id
                        }
                    }).then(function(result) {
                        if (result && result.orders) {
                            return result.orders[0];
                        } else {
                            return reject("未找到order_id：" + order_id);
                        }
                    });
                }

                //退款
                function refundAdd(order_id) {
                    if (order_id) {
                        return requestApi("/rest/v1/pay/refund/add", order_id).then(function(result) {
                            return result;
                        });
                    }
                }

                //订单发货
                function orderDeliveryUpdate(data) {
                    if (data) {
                        return requestApi("/rest/v1/order/delivery/update", data).then(function(result) {
                            return result;
                        });
                    }
                }

                //订单确认
                function orderConfirmUpdate(data) {
                    if (data) {
                        return requestApi("/rest/v1/order/confirm/update", data).then(function(result) {
                            return result;
                        });
                    }
                }

                //订单关闭
                function orderCloseUpdate(data) {
                    if (data) {
                        var isdata = clone(data);
                        // isdata.order = angular.toJson(isdata.order);
                        return requestApi("/rest/v1/order/close/update", isdata).then(function(result) {
                            return result;
                        });
                    }
                }

                function orderCancelUpdate(data) {
                    if (data) {
                        var isdata = clone(data);
                        return requestApi("/rest/v1/order/cancel/update", isdata).then(function(result) {
                            return result;
                        });
                    }
                }

                //订单状字段
                function orderUpdate(data) {
                    if (data) {
                        var isdata = clone(data);
                        // isdata.order = angular.toJson(isdata.order);
                        return requestApi("/rest/v1/order/update", isdata).then(function(result) {
                            return result;
                        });
                    }
                }

                // 分销售后查询
                function returnformGet(data) {
                    if (data) {
                        return requestApi("/rest/v1/returnform/get", data).then(function(result) {
                            return result;
                        });
                    }
                }
                //单个售后单
                function returnformOne(return_form_id) {
                    return returnformGet({
                        query: {
                            return_form_id: return_form_id
                        }
                    }).then(function(result) {
                        if (result && result.return_forms) {
                            return result.return_forms[0];
                        } else {
                            return "未找到return_form_id：" + return_form_id;
                        }
                    });
                }
                // /rest/v1/returnform/status/update
                // 分销流转状态
                function returnformStatusUpdate(data) {
                    if (data) {
                        return requestApi("/rest/v1/returnform/status/update", data).then(function(result) {
                            return result;
                        });
                    }
                }
                // 分销售后的删除
                function returnformDelete(data) {
                    if (data) {
                        return requestApi("/rest/v1/returnform/delete", data).then(function(result) {
                            return result;
                        });
                    }
                }
                //分销售后修改
                function returnformUpdate(data) {
                    if (data) {
                        return requestApi("/rest/v1/returnform/update", data).then(function(result) {
                            return result;
                        });
                    }
                }
                // 分销售后添加
                function returnformAdd(data) {
                    var xdata = clone(data);
                    xdata.in_items = angular.toJson(xdata.in_items);
                    xdata.out_items = angular.toJson(xdata.out_items);
                    if (xdata) {
                        return requestApi("/rest/v1/returnform/add", xdata).then(function(result) {
                            return result;
                        });
                    }
                }
                //商品字段中float32类型字段处理
                function itemFloat32(data) {
                    var f32 = ["input_total_fee", "out_total_fee", "total_payment", "discount_fee", "sku_input_price", "sku_out_price", "price", "sku_weight", "input_price", "output_price", "weight", "volume", "status_id"];
                    if (_.isArray(data.skus)) {
                        _.map(data.skus, function(s, sk) {
                            _.map(s, function(a, ak) {
                                if (f32.indexOf(ak) != -1) {
                                    data.skus[sk][ak] = parseFloat(a);
                                }
                            });
                        });
                    }

                    _.map(data, function(a, ak) {
                        if (f32.indexOf(ak) != -1) {
                            data[ak] = parseFloat(a);
                        }
                    });
                    return data;
                }
                // 提现查询
                function cashreqGet(data) {
                    if (data) {
                        return requestApi("/rest/v1/cashreq/get", data).then(function(result) {
                            if (result.cash_reqs) {
                                _.map(result.cash_reqs, function(v, k) {
                                    result.cash_reqs[k].pay_time = currentTime(v.pay_time);
                                });
                                return result;
                            }
                        });
                    }
                }
                //查询一条数据
                function cashreqOne(id) {
                    if (id) {
                        var query = {
                            cash_req_id: id
                        };
                        return cashreqGet({
                            query: query
                        }).then(function(result) {
                            if (result) {
                                if (result && result.cash_reqs) {
                                    return result.cash_reqs[0];
                                } else {
                                    return "未找到cash_req_id：" + cash_req_id;
                                }
                            }
                        });
                    }
                }

                function cashreqUpdate(data) {
                    if (data) {
                        return requestApi("/rest/v1/cashreq/update", data).then(function(result) {
                            return result;
                        });
                    }
                }
                //添加 提现
                function cashreqAdd(data) {
                    if (data) {
                        var xdata = clone(data);
                        xdata.pay_time = toStdTime(xdata.pay_time);

                        return requestApi("/rest/v1/cashreq/add", xdata).then(function(result) {
                            return result;
                        });
                    }
                }
                //查询供应商 /rest/v1/suppliers/get
                function sellerSuppliersGet(data) {
                    if (data) {
                        return requestApi("/rest/v1/suppliers/get", data).then(function(result) {
                            if (result) {
                                return result;
                            }
                        });
                    }
                }

                //查询供应商 /rest/v1/suppliers/get
                function sellerSuppliersOne(company_id) {
                    if (company_id) {
                        return sellerSuppliersGet({
                            query: {
                                "company_id": company_id
                            }
                        }).then(function(result) {
                            if (result.company) {
                                return result.company[0];
                            }
                        });
                    }
                }

                //授权 /rest/v1/cooperation/get
                function sellercooperationGet(data) {
                    if (data) {
                        return requestApi("/rest/v1/cooperation/get", data).then(function(result) {
                            if (result) {
                                return result;
                            }
                        });
                    }
                }
                //授权 /rest/v1/cooperation/get
                function sellercooperationOne(data) {
                    if (data) {
                        return sellercooperationGet(data).then(function(result) {
                            if (result) {
                                return result.shop[0];
                            }
                        });
                    }
                }
                //分销商授权添加
                function sellercooperationAdd(data) {
                    if (data) {
                        var xdata = sellercooperationTime(data);
                        return requestApi("/rest/v1/cooperation/add", xdata).then(function(result) {
                            if (result) {
                                return result;
                            }
                        });
                    }
                }
                //分销商授权修改
                function sellercooperationUpdate(data) {
                    if (data) {
                        var xdata = sellercooperationTime(data);
                        return requestApi("/rest/v1/cooperation/update", xdata).then(function(result) {
                            if (result) {
                                return result;
                            }
                        });
                    }
                }

                //分销商授权删除
                function sellercooperationDel(data) {
                    if (data) {
                        return requestApi("/rest/v1/cooperation/delete", data).then(function(result) {
                            if (result) {
                                return result;
                            }
                        });
                    }
                }

                //商品sku类型获取 例如 颜色类型
                function itemSkuTypeGet(data) {
                    //                     console.error("data", data);
                    return requestApi("/rest/v1/skutype/get", data).then(function(result) {
                        return result;
                    });
                }
                //商品sku类型添加
                function itemSkuTypeAdd(data) {
                    return requestApi("/rest/v1/skutype/add", data).then(function(result) {
                        return result;
                    });
                }
                //商品sku类型 修改
                function itemSkuTypeUpdate(data) {
                    return requestApi("/rest/v1/skutype/update", data).then(function(result) {
                        return result;
                    });
                }
                //商品sku类型删除
                function itemSkuTypeDel(data) {
                    return requestApi("/rest/v1/skutype/delete", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型值获取 例如 红色  
                function itemSkuValueGet(data) {
                    return requestApi("/rest/v1/skuvalue/get", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型 值 添加
                function itemSkuValueAdd(data) {
                    return requestApi("/rest/v1/skuvalue/add", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型 值 获取
                function itemSkuValueUpdate(data) {
                    return requestApi("/rest/v1/skuvalue/update", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型 值 删除
                function itemSkuValueDel(data) {
                    return requestApi("/rest/v1/skuvalue/delete", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型 值 删除
                function productGet(data) {
                    return requestApi("/rest/v1/product/get", data).then(function(result) {
                        return result;
                    });
                }

                //商品sku类型 值 删除
                function productUpdate(data) {
                    return requestApi("/rest/v1/product/sync/update", data).then(function(result) {
                        return result;
                    });
                }

                //s查询数据
                function webTokenGet(data, show) {
                    return requestApi("/public/web/token/get", data).then(function(result) {
                        // var  result = {};
                        // result.token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJDdXJyZW50VXNlciI6eyJJZCI6MTcwNzIwMywiQ29tcGFueUlkIjoxNzA3MjAyLCJSb2xlIjoyfSwiZXhwIjoxNTAxMDUyMzMxfQ.tZ1R6jpMC7UJQh18V3dXCfzfzLPiEoZbS573EmNKlTk";
                        if (result.token) {

                            /*****************************
                             * Role的字段，数字类型： 1 表示买家 2 表示卖家 3 表示供应商 4 表示管理者
                             * 
                             ******************************/

                            var decoded = jwt_decode(result.token);

                            // var testToken = {
                            //     "CurrentUser": {
                            //         "Id": 1705112,
                            //         "CompanyId": 1705112,
                            //         "Role": 2,
                            //         "ShopId": 1
                            //     },
                            //     "exp": 1495041416
                            // };

                            // testToken.CurrentUser.Id = decoded.CurrentUser.Id
                            // testToken.CurrentUser.CompanyId = decoded.CurrentUser.CompanyId
                            // decoded.open_id = "omg4M0R0trvcY-n1nPcS3IeAzoCA";
                            // decoded.token = result.token;
                            //                             console.error("result.token:----", decoded);
                            if (!show) {
                                sessionService.put("token", result.token);
                                sessionService.put("tokenUser", decoded.CurrentUser);
                                sessionService.put("store", null);
                            }
                        }
                        return result;
                    });
                }

                //获取配置
                function subuserGet(data) {
                    return requestApi('/rest/v1/subuser/get', data).then(function(result) {
                        return result;
                    });
                }

                //happ ui 获取配置
                function wxappOne(data) {

                    var query = {
                        app_id: data.appid
                    };
                    if (data.store_id) {
                        query.store_id = data.store_id;
                    }
                    if (data.cid) {
                        query.wxapp_cfg_id = data.cid;
                    }

                    if (data.name) {
                        query.name = data.name;
                    }

                    return wxappGet({
                        query: query
                    }).then(function(result) {
                        return result.wxappcfg[0];
                    });
                }

                function wxappGet(data) {
                    data.order_by = "wxapp_cfg_id:desc";
                    return requestApi('/public/wxappcfg/get', data).then(function(result) {
                        return result;
                    });
                }

                function wxappAdd(data) {
                    data.value = angular.toJson(data.value);
                    return requestApi("/rest/v1/wxappcfg/add", data).then(function(result) {
                        return result;
                    });
                }

                function wxappUpdate(data) {
                    data.value = angular.toJson(data.value);
                    return requestApi("/rest/v1/wxappcfg/update", data).then(function(result) {
                        return result;
                    });
                }

                function wxappDelete(data) {
                    return requestApi("/rest/v1/wxappcfg/delete", data).then(function(result) {
                        return result;
                    });
                }

                //hq获取配置
                function shopconfigGet(data) {
                    data.order_by = "shop_config_id:desc";
                    return requestApi('/rest/v1/shopconfig/get', data).then(function(result) {
                        return result;
                    });
                }

                function shopConfigAdd(data) {
                    data.value = angular.toJson(data.value);
                    return requestApi("/rest/v1/shopconfig/add", data).then(function(result) {
                        return result;
                    });
                }

                function shopConfigUpdate(data) {
                    data.value = angular.toJson(data.value);
                    return requestApi("/rest/v1/shopconfig/update", data).then(function(result) {
                        return result;
                    });
                }

                function shopConfigDelete(data) {
                    return requestApi("/rest/v1/shopconfig/delete", data).then(function(result) {
                        return result;
                    });
                }


                function shopConfigOne(id) {
                    return shopconfigGet({
                        query: {
                            "shop_config_id": id
                        }
                    }).then(function(result) {
                        return result.shopconfigs[0];
                    });
                }

                function shopConfigOneByKey(field, type, subtype) {
                    //                     console.error("111fff",field,type)
                    var query = {
                        "field": field
                    };
                    if (type) {
                        query["types"] = type;
                    }

                    if (subtype) {
                        query["subtype"] = subtype;
                    }

                    return shopconfigGet({
                        query: query
                    }).then(function(result) {
                        return result.shopconfigs[0];
                    });
                }

                // 公共模板查询 
                function printPubGet(data) {
                    return requestApi("/rest/v1/printpub/get", data).then(function(result) {
                        return result;
                    });
                }

                // 公共模板查询 
                function printPubOne(print_pub_id) {
                    return printPubGet({
                        query: {
                            "print_pub_id": print_pub_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return result;
                        } else {
                            return result.prints ? result.prints[0] : result.prints;
                        }
                    });
                }

                //公共模板添加
                function printPubAdd(data) {
                    if (data) {
                        var xdata = clone(data);
                        if (xdata.content) {
                            xdata.content = angular.toJson(xdata.content);
                        }
                    }
                    return requestApi("/rest/v1/printpub/add", xdata).then(function(result) {
                        return result;
                    });
                }
                // 公共模板的修改
                function printPubUpdate(data) {
                    if (data) {
                        var xdata = clone(data);
                        if (xdata.content) {
                            xdata.content = angular.toJson(xdata.content);
                        }
                    }
                    return requestApi("/rest/v1/printpub/update", xdata).then(function(result) {
                        return result;
                    });
                }
                // 公共模板的修改
                function printPubDelete(data) {
                    return requestApi("/rest/v1/printpub/delete", data).then(function(result) {
                        return result;
                    });
                }

                // 商家模板的发布
                function printSellerAdd(data) {
                    if (data) {
                        var xdata = clone(data);
                        if (xdata.content) {
                            xdata.content = JSON.stringify(xdata.content);
                        }
                        return requestApi("/rest/v1/print/add", xdata).then(function(result) {
                            return result;
                        });
                    }
                }


                // 商家模板的修改
                function printSellerUpdate(data) {
                    if (data) {
                        var xdata = clone(data);
                        if (xdata.content) {
                            xdata.content = angular.toJson(xdata.content);
                        }

                    }
                    return requestApi("/rest/v1/print/update", xdata).then(function(result) {
                        return result;
                    });
                }

                // 商家模板的删除
                function printSellerDelete(data) {
                    return requestApi("/rest/v1/print/delete", data).then(function(result) {
                        return result;
                    });
                }
                // 商家模板的查询
                function printSellerGet(data) {
                    return requestApi("/rest/v1/print/get", data).then(function(result) {
                        return result;
                    });
                }

                // 商家模板查询 
                function printSellerOne(print_id) {
                    return printSellerGet({
                        query: {
                            "print_id": print_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return false;
                        } else {
                            return result.prints[0] ? result.prints[0] : result.prints;
                        }
                    });
                }

                // 评价查询  
                function reviewGet(data) {
                    return requestApi("/public/review/get", data).then(function(result) {
                        return result;
                    });
                }

                // 评价查询  
                function reviewOne(id) {
                    return reviewGet({
                        query: {
                            "review_id": id
                        }
                    }).then(function(result) {
                        return result.review[0] ? result.review[0] : "";
                    });
                }



                //活动 添加  
                function activitypageAdd(data) {
                    return requestApi("/rest/v1/activitypage/add", data).then(function(result) {
                        return result;
                    });
                }

                //活动 查询
                function activitypageGet(data) {
                    return requestApi("/public/activitypage/get", data).then(function(result) {
                        _.map(result.activity_pages, function(da, ke) {
                            try {
                                da.content = da.content ? json2html(JSON.parse(da.content)) : da.content;
                            } catch (e) {
                                console.error("content出错：", da);
                                da.content = {};
                            }
                        });
                        return result;
                    });
                }
                //活动 删除 
                function activitypageDel(data) {
                    return requestApi("/rest/v1/activitypage/delete", data).then(function(result) {
                        return result;
                    });
                }
                //活动 修改
                function activitypageUpdate(data) {
                    return requestApi("/rest/v1/activitypage/update", data).then(function(result) {
                        return result;
                    });
                }
                //活动查询单条 
                function activitypageOne(a_id) {
                    return activitypageGet({
                        query: {
                            "activity_page_id": a_id
                        }
                    }).then(function(result) {
                        if (result.Msg) {
                            return false;
                        } else {
                            return result.activity_pages[0] ? result.activity_pages[0] : result.activity_pages;
                        }
                    });
                }

                //x添加小程序版本
                function userappAdd(data) {
                    var query = {};
                    query.query = {
                        "app_id": data.app_id,
                        "template_id": data.template_id
                    };
                    return userappGet(query).then(function(reis) {
                        if (reis.user_apps.length > 0) {
                            var updata = clone(data);
                            updata.user_app_id = reis.user_apps[0].user_app_id;
                            return userappUpdate(updata).then(function(up) {
                                // return saveStoreCodeStatus(data.store_id, data.app_id, { template_id: data.template_id });
                                return up;
                            });
                        } else {
                            return requestApi("/rest/v1/userapp/add", data).then(function(result) {
                                // return saveStoreCodeStatus(data.store_id, data.app_id, { template_id: data.template_id });
                                return result;
                            });
                        }
                    })
                }

                //修改小程序版本
                function userappUpdate(data) {
                    return requestApi("/rest/v1/userapp/update", data).then(function(result) {
                        return result;
                    });
                }


                //查询小程序版本
                function userappGet(data) {
                    data.order_by = data.order_by || "user_app_id:desc";
                    return requestApi("/rest/v1/userapp/get", data).then(function(result) {
                        return result;
                    });
                }


                //删除小程序版本
                function userappDelete(data) {
                    return requestApi("/rest/v1/userapp/delete", data).then(function(result) {
                        return result;
                    });
                }

                //添加用户
                function bindAdd(data) {
                    return requestApi("/rest/v1/bind/add", data).then(function(result) {
                        return result;
                    });
                }
                //j解除 绑定关系
                function bindDelete(data) {
                    return requestApi("/rest/v1/bind/delete", data).then(function(result) {
                        return result;
                    });
                }



                //j查询公司列表
                function v1PartnerGet(data, nocache) {
                    var ttl = nocache ? 0 : 24 * 3600;
                    data = data || {};

                    return requestApi("/rest/v1/partner/get", data, ttl).then(function(result) {
                        return result;
                    });
                }

                //公司列表添加
                function v1PartnerAdd(data) {
                    return requestApi("/public/seller/register", data).then(function(result) {
                        return result;
                    });
                }
                //公司列表添加
                function v1PartnerUpdate(data) {
                    return requestApi("/rest/v1/partner/update", data).then(function(result) {
                        return result;
                    });
                }

                //生成二维码
                function webQrcodeGet(data) {
                    data.base64 = true;
                    return requestApi("/public/web/qrcode/get", data, 0, "get").then(function(result) {
                        return result;
                    });
                }

                //生成公众号二维码
                function wxQrcodeGet(authorizer_appid, data) {
                    return this.wxproxy(authorizer_appid, "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN", "POST", data).then(function(result) {
                        if (result.url) {
                            return webQrcodeGet({
                                code: result.url
                            });
                        } else {
                            return false;
                        }
                    });
                }

                //获取商家
                function sellerGet(data) {
                    return requestApi("/rest/v1/seller/get", data).then(function(result) {
                        return result;
                    });
                }

                //获取商家
                function memberGet(data, ttl) {
                    return requestApi("/rest/v1/member/get", data, ttl ? 0 : 24 * 3600).then(function(result) {
                        return result;
                    });
                }

                function memberUpdate(data) {
                    return requestApi("/rest/v1/buyer/update", data).then(function(result) {
                        return result;
                    });
                }

                //获取会员帐户值
                function accountvaleGet(data) {
                    return requestApi("/rest/v1/account/get", data).then(function(result) {
                        return result;
                    });
                }

                //q添加会员等级
                function memberlevelAdd(data) {
                    return requestApi("/rest/v1/memberlevel/add", data).then(function(result) {
                        return result;
                    });
                }

                function memberlevelUpdate(data) {
                    return requestApi("/rest/v1/memberlevel/update", data).then(function(result) {
                        return result;
                    });
                }

                //q获取会员等级
                function memberlevelGet(data) {
                    return requestApi("/rest/v1/memberlevel/get", data).then(function(result) {
                        return result;
                    });
                }


                //q获取用户微信信息
                function basicinfoGet(data) {
                    return requestApi("/rest/v1/seller/basicinfo/get", data, 24 * 3600).then(function(result) {
                        return result;
                    });
                }

                function sellercooperationTime(data) {
                    var xdata = clone(data);
                    if (xdata.start_date && xdata.end_date && xdata.seller_agree_time) {
                        xdata.start_date = toStdTime(xdata.start_date);
                        xdata.end_date = toStdTime(xdata.end_date);
                        xdata.seller_agree_time = toStdTime(xdata.seller_agree_time);
                    }
                    return xdata;
                }

                //缓存one类型的数据
                function oneCacheSet(funcName, xid, data, ttl) {
                    ttl = ttl || 30 * 60;
                    var questKey = funcName + "_" + xid;
                    // console.log(funcName, " 写入缓存：", questKey, data);
                    cacheService.set(questKey, data, ttl);
                    return data;
                }

                function oneCacheDel(funcName, xid) {
                    var questKey = funcName + "_" + xid;
                    // console.log(funcName, " 删除缓存：", questKey);
                    cacheService.del(questKey);
                }


                /*************************王苍 end *****************************************************/

                /*************************郭 start *****************************************************/

                //1、获取预授权
                function authorizePreAuthCodeGet(data) {
                    return requestApi("/rest/v1/authorize/pre_auth_code/get", data).then(function(result) {
                        return result;
                    });
                }

                //2、使用授权码换取公众号或小程序的接口调用凭据和授权信息
                function authorizeAuthCodeGet(component_appid, authorization_code, store_id) {
                    return requestApi("/rest/v1/authorize/auth_code/get", {
                        component_appid: component_appid,
                        authorization_code: authorization_code,
                        store_id: store_id
                    }).then(function(result) {
                        if (result) {
                            return result;
                        }
                    });
                }

                function storeAppAdd(data) {
                    if (data.content) {
                        data.content = JSON.stringify(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/store/app/add", data).then(function(result) {
                        return result;
                    });
                }

                function storeAppDel(data) {
                    if (data.content) {
                        data.content = JSON.stringify(data.content);
                    }
                    return requestApi("/rest/v1/php/dhf/store/app/delete", data).then(function(result) {
                        return result;
                    });
                }

                function storeApplistGet(data) {
                    if (data.content) {
                        data.content = JSON.stringify(data.content);
                    }
                    return requestApi("/public/php/dhf/store/app/get", data).then(function(result) {
                        return result;
                    });
                }

                function storeAppAllGet(data) {
                    return requestApi("/rest/v1/authorize/authorizer_info/get", data).then(function(result) {
                        return result;
                    });
                }

                function getCustaccount(data) {
                    if (data.content) {
                        data.content = JSON.stringify(data.content);
                    }
                    // console.error("fffffffffffffffffffffffffdata", data);
                    return requestApi("/rest/v1/php/dhf/store/related/apps/get", data).then(function(result) {
                        return result;
                    });
                }
                //3、查询店铺授权的app信息列表
                // function sellerAuthorizeAuthorizer_infoGet(store_id, service_type_id, nocache) {
                //     var query = {};
                //     if (store_id) {
                //         query.store_id = Number(store_id);
                //     }
                //     if (service_type_id) {
                //         query.service_type_id = Number(service_type_id);
                //     }
                //     // nocache ? 0 : 300
                //     return requestApi("/rest/v1/authorize/authorizer_info/get", query).then(function(result) {
                //         console.error("resffffffffffffffffffffffffult", result);
                //         if (service_type_id) {
                //             var a = [];
                //             _.map(result, function(z) {
                //                 if (z.expires_in <= 0) {
                //                     helper.myAlert("授权掉线了，需要重新授权才能继续！", "#/store/config?store_id=" + z.store_id);
                //                     return reject();
                //                 }
                //                 if (z.service_type_id == service_type_id) {
                //                     a.push(z);
                //                 }
                //             });
                //             return a;
                //         } else {
                //             _.map(result, function(z) {
                //                 if (z.expires_in <= 0) {
                //                     helper.myAlert("授权掉线了，需要重新授权才能继续！", "#/store/config?store_id=" + z.store_id);
                //                     return reject();
                //                 }
                //             });
                //             return result;
                //         }
                //     });
                // }
                //3、查询店铺授权的app信息列表
                function sellerAuthorizeAuthorizer_infoGet(store_id, service_type_id, nocache) {
                    var query = {
                        content: {}
                    };
                    if (store_id) {
                        query.content.store_id = Number(store_id);
                    }
                    if (service_type_id) {
                        query.content.service_type_id = Number(service_type_id);
                    }
                    if (query.content) {
                        query.content = JSON.stringify(query.content);
                    }
                    // nocache ? 0 : 300
                    return requestApi("/rest/v1/php/dhf/store/related/apps/get", query, nocache ? 0 : 300).then(function(result) {
                        if (service_type_id) {
                            var a = [];
                            _.map(result, function(z) {
                                if (z.expires_in <= 0) {
                                    // helper.myAlert("授权掉线了，需要重新授权才能继续！", "#/store/config?store_id=" + z.store_id);
                                    helper.myAlert("授权掉线了，需要重新授权才能继续！");
                                    return reject();
                                }
                                if (z.service_type_id == service_type_id) {
                                    a.push(z);
                                }
                            });
                            return a;
                        } else {
                            _.map(result, function(z) {
                                if (z.expires_in <= 0) {
                                    // helper.myAlert("授权掉线了，需要重新授权才能继续！", "#/store/config?store_id=" + z.store_id);
                                    helper.myAlert("授权掉线了，需要重新授权才能继续！");
                                    return reject();
                                }
                            });
                            return result;
                        }
                    });
                }

                //获取单个授权app信息
                function wxappAuthorizerOne(store_id, wxappid) {
                    var c;
                    return sellerAuthorizeAuthorizer_infoGet(store_id).then(function(result) {
                        _.map(result, function(a) {
                            if (a.app_id === wxappid) {
                                c = a;
                            }
                        });

                        return c;
                    });
                }

                //发布目录设置
                function sellerCodeGetCategoryGet(authorizer_appid) {
                    return requestApi("/rest/v1/code/get_category/get", {
                        authorizer_appid: authorizer_appid
                    }).then(function(result) {
                        return result;
                    });
                }

                //获取页面配置
                function sellerCodePageGet(authorizer_appid) {
                    return requestApi("/rest/v1/code/page/get", {
                        authorizer_appid: authorizer_appid
                    }).then(function(result) {
                        return result;
                    });
                }

                //代码提交审核
                function domainUpdate(authorizer_appid, action, requestdomain, wsrequestdomain, uploaddomain, downloaddomain) {
                    return requestApi("/rest/v1/domain/update", {
                        authorizer_appid: authorizer_appid,
                        action: action,
                        requestdomain: requestdomain,
                        uploaddomain: uploaddomain,
                        downloaddomain: downloaddomain,
                        wsrequestdomain: wsrequestdomain
                    }).then(function(result) {
                        if (result.code == 0 && result.Msg) {
                            return JSON.parse(result.Msg);
                        } else {
                            return result;
                        }
                    });
                }

                //消息获取
                function notifyGet(data) {
                    data = data || {};
                    data.order_by = data.order_by || "notify_id:desc";
                    return requestApi("/rest/v1/notify/get", data).then(function(result) {
                        return result;
                    });
                }

                //一个消息
                function notifyOne(notify_id) {
                    return notifyGet({
                        query: {
                            "notify_id": notify_id
                        }
                    }).then(function(result) {
                        if (result.notifys && result.notifys[0]) {
                            return result.notifys[0];
                        } else {
                            return result;
                        }
                    });
                }

                //消息添加
                function isvNotifyAdd(data) {
                    return requestApi("/rest/v1/notify/add", data).then(function(result) {
                        return result;
                    });
                }

                //消息更新
                function isvNotifyUpdate(data) {
                    return requestApi("/rest/v1/notify/update", data).then(function(result) {
                        return result;
                    });
                }

                //消息删除
                function isvNotifyDelete(notify_id) {
                    return requestApi("/rest/v1/notify/delete", {
                        notify_id: notify_id
                    }).then(function(result) {
                        return result;
                    });
                }



                //模块获取
                function uimodsGet(data) {
                    data = data || {};
                    data.order_by = data.order_by || "uimods_id:desc";
                    return requestApi("/public/uimods/get", data).then(function(result) {
                        return result;
                    });
                }

                //一个模块
                function uimodsOne(uimods_id) {
                    return uimodsGet({
                        query: {
                            "uimods_id": uimods_id
                        }
                    }).then(function(result) {
                        if (result.uimods && result.uimods[0]) {
                            result.uimods[0].data = JSON.parse(result.uimods[0].data);
                            return result.uimods[0];
                        } else {
                            return result;
                        }
                    });
                }

                //模块添加
                function uimodsAdd(data) {
                    var xdata = clone(data);
                    xdata.data = angular.toJson(xdata.data);
                    return requestApi("/rest/v1/uimods/add", xdata).then(function(result) {
                        return result;
                    });
                }

                //模块更新
                function uimodsUpdate(data) {
                    var xdata = clone(data);
                    xdata.data = angular.toJson(xdata.data);
                    delete xdata.created_at;
                    delete xdata.updated_at;
                    return requestApi("/rest/v1/uimods/update", xdata).then(function(result) {
                        return result;
                    });
                }

                //模块删除
                function uimodsDelete(uimods_id) {
                    return requestApi("/rest/v1/uimods/delete", {
                        uimods_id: uimods_id
                    }).then(function(result) {
                        return result;
                    });
                }

                /*************************王苍 end *****************************************************/

                //通用请求
                function requestApi(path, data, ttl, method) {
                    //开发模式下，ttl设置为0
                    // ttl = 0;
                    // console.error("api请求1：",ttl, ERP_CONFIG.apiUrl + path, data, angular.toJson(data));
                    data = data ? data : {};

                    if (data.start_created) {
                        data.start_created = toStdTime(data.start_created);
                    }

                    if (data.end_created) {
                        data.end_created = toStdTime(data.end_created);
                    }

                    var token = sessionService.get('token');
                    if (token) {
                        data.token = token;
                    }

                    if ("page_size" in data) {
                        if (!_.isNumber(data.page_size)) {
                            data.page_size = 10;
                        }
                    }

                    if ("page_no" in data) {
                        if (!_.isNumber(data.page_no)) {
                            data.page_no = 1;
                        }
                    }

                    //缓存
                    if (ttl) {
                        var questKey = md5.createHash(path + angular.toJson(data));
                        var cacheVal = cacheService.get(questKey, ttl);
                        if (cacheVal) {
                            // console.error("api命中缓存：", questKey, path, data, cacheVal);
                            return returnData(cacheVal);
                        } else {
                            // console.error("没有查到缓存：", questKey, cacheVal);
                        }
                    }

                    //组装query字段
                    if (data.query && !_.isObject(data.query)) {
                        return helper.message("query不是object：" + data.query, "error", 15);
                    }

                    if (data.query && _.isObject(data.query)) {
                        var queryTmp = [];
                        _.map(data.query, function(v, k) {
                            queryTmp.push(k + ":" + v);
                        });
                        data.query = queryTmp.join(",");
                    }

                    if (data.subquery && _.isObject(data.subquery)) {
                        var queryTmp = [];
                        _.map(data.subquery, function(v, k) {
                            queryTmp.push(k + ":" + v);
                        });
                        data.subquery = queryTmp.join(",");
                    }

                    var headers = null;
                    if (path === "php") {
                        var trueUrl = ERP_CONFIG.api2Url + "/api2/rest/";
                    } else {
                        var trueUrl = ERP_CONFIG.apiUrl + path;
                    }

                    if (!method) {
                        var httpMethod = "POST";
                        var params = null;
                        var requestData = data;
                        if (token) {
                            requestData.token = token;
                        }
                    } else {
                        var httpMethod = "GET";
                        var params = data;
                        var requestData = null;
                        if (token) {
                            //console.error("-------", path, path.indexOf("/rest/v1/"));
                            if (path.indexOf("/rest/v1/") === 0) {
                                headers = {
                                    Authorization: token
                                };
                                //console.error("-------", headers);
                            }
                        }
                    }

                    if ($rootScope.store_id) {
                        if (!headers) {
                            headers = {
                                dhfbackstoreid: $rootScope.store_id
                            };
                        } else {
                            headers.dhfbackstoreid = $rootScope.store_id;
                        }
                    }

                    // console.log("bbbbbbb", trueUrl, requestData);
                    return $http({
                        method: httpMethod,
                        url: trueUrl,
                        params: params,
                        data: requestData,
                        headers: headers,
                    }).then(function(res) {
                        var result = clone(res.data);
                        if (ttl) {
                            // console.log("存入缓存：", path, questKey, data, result);
                            if (result && !result.Err) {
                                cacheService.set(questKey, result, ttl);
                            }
                        }
                        // console.log("api请求2：", httpMethod, trueUrl, params, requestData, headers, "返回：", JSON.parse(angular.toJson(result)));

                        return returnData(result);
                    }, function(response) {
                        if (response.status == 403) {
                            // if (path.indexOf("/add") != -1 || path.indexOf("/update") != -1 || path.indexOf("/delete") != -1) {

                            helper.message("缺少权限：" + requestData.method ? requestData.method : path, "error", 15);
                            // }
                            return {
                                Err: 1,
                                Msg: "Need permission:" + path
                            };
                        } else if (response.status === 406) {
                            //需要申请授权的API
                            var Msg = response.data.Msg;
                            return {
                                Err: 1,
                                Msg: Msg + " 联系商家处理！",
                                errmsg: Msg + " 联系商家处理！"
                            };
                        } else {
                            console.log("http error:", response);
                            return {
                                Err: 1,
                                Msg: "error...."
                            };
                        }
                    });
                }

                function buildQuery(obj, prefix) {
                    var str = [];
                    for (var p in obj) {
                        if (obj.hasOwnProperty(p)) {
                            var k = prefix ? prefix + "[" + p + "]" : p,
                                v = obj[p];
                            str.push(typeof v == "object" ?
                                buildQuery(v, k) :
                                encodeURIComponent(k) + "=" + encodeURIComponent(v));
                        }
                    }
                    return str.join("&");
                }

                //总返回数据
                function returnData(data) {
                    var timeKeys = ['paid_time', 'created_at', 'update_at', 'updated_at', 'pre_in_time', 'produce_time', 'expire_time', 'pay_time', 'start_date', 'end_date', 'seller_agree_time', 'start_time', 'end_time', 'huodong_start_time', 'huodong_end_time', 'sign_time', 'upload_time', 'publish_time', 'subaduit_time', 'order_cycle_start', 'order_cycle_end', 'created_time', 'expiry_time', 'class_time', 'class_tiem', 'order_time', 'expiration_time', 'receiver_time', 'time', 'withdrawal_time', 'updated_time', 'fz_time'];
                    if (_.isArray(data) || _.isObject(data)) {
                        _.map(data, function(v, k) {
                            if (_.isString(v) && timeKeys.indexOf(k) != -1) {
                                data[k] = currentTime(v);
                            }

                            if (_.isArray(v) || _.isObject(v)) {
                                _.map(v, function(v1, k1) {
                                    if (_.isString(v1) && timeKeys.indexOf(k1) != -1) {
                                        data[k][k1] = currentTime(v1);
                                    }

                                    if (_.isArray(v1) || _.isObject(v1)) {
                                        _.map(v1, function(v2, k2) {
                                            if (_.isString(v2) && timeKeys.indexOf(k2) != -1) {
                                                data[k][k1][k2] = currentTime(v2);
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                    // console.error("222222",JSON.parse(angular.toJson(data)));

                    return resolve(data);
                }

                //把标准时间变成当地时间
                function currentTime(utcTime) {
                    // return moment.tz(utcTime, "Etc/UTC").tz(moment.tz.guess()).format("YYYY-MM-DD HH:mm:ss");
                    var timezone;
                    if (window.localStorage.timezone) {
                        timezone = window.localStorage.timezone;
                    } else {
                        timezone = moment.tz.guess();
                    }

                    return moment.tz(utcTime, "Etc/UTC").tz(timezone).format("YYYY-MM-DD HH:mm:ss");
                }

                //把当地变成标准时间
                function toStdTime(x) {
                    return $filter('stdTime')(x);
                }

                //返回promis
                function resolve(res) {
                    // console.log("resolve:", res);
                    var def = $q.defer();
                    def.resolve(res);
                    return def.promise;
                }

                function reject(res) {
                    console.log("reject:", res);
                    return $q.reject(res);
                }

                function promise() {
                    return $q.when(true);
                }

            }
        ]);
})();